Hi,
I'm trying to launch asynchronous method on serie way with async, But, you guess it, I can't did it.
Here is my code :
function findParam(userKey,callback){
console.log("looking for params "+userKey);
params.get(userKey,
function(err, result, key) {
var param = result;
param.key=key;
console.log("findParam "+param);
callback(err, userKey, param);
});
console.log("done");
}
function findUsers(userKey,param, callback){
console.log("looking fo uers "+userKey);
console.log("Param "+param);
users.get(userKey,
function(err, result, key) {
var user = result;
user.key=key;
console.log("user "+user);
callback(err, user, param);
});
}
launch code :
var user = findUserBySession(req.sessionID);
async.waterfall(
[
findParam(user.key, callback),
findUsers(arg1, arg2, callback)
]);
the stack trace :
looking for params 3edgl89
done
ReferenceError: arg1 is not defined... (lot of errors)
findParam [object Object]
That stack trace revealed to me that the second method is launched before the param was found. This is why the error appeared.
Can you help me ? What have I done wrong ?
Thank you !