Sunday, 25 August 2013

Node.js async consistency

Node.js async consistency

I have the following code :
server.use(function(req, res, next) {
users_db.set(req.user, function(err) { // async call to mongodb
if (err) {
console.error(err);
}
});
}
return next();
});
server.get('/', function(req, res) {
req.user.active = true; // this is a new field in user object
res.send(req.user);
}
});
So, As you see, when users_db.set() is called, req.user doesn't have the
active=true field. It is being inserted only in the server.get() function.
Is it possible that user.active = true is registered in the db
nevertheless because of the asynchronous nature of the call ?

No comments:

Post a Comment