I have a feeling I\'ve made an obvious mistake, but can\'t find it.
The error I get is:
node_modules/async/lib/async.js:194
iterator(x.value,
Async expects a non-sparse array, but I'm guessing, based on your usage of 'i' as userid, that newProfiles is sparsely populated and indexed by userid.
Also, the first argument to iterator is the actual value from the array ('profile'), not the index ('i'). Also, calling 'userids.push(userid)' after you have passed 'callback' into createProfile is bad form. You shoudl do this instead.
createProfile(userid, serviceName, profile, function() {
userids.push(userid);
callback();
});
Overall though, there are a few possible ways to fix the sparseness issue. For instance you could try to use async.parallel, and pass an object indexed by key instead.
But first I wanted to ask, won't using sparseness to indicate creating new profiles just cause massive amounts of userid collision? As soon as you called createProfiles twice with the first item sparse, it will try to create a second profile with userid = 0. Generally when you want to create something new, you would actually have 'createProfile' generate and return the new ID.