First question here :D
I am trying to deal with an edge case with user account creation using node.js and mongodb, where user or users attempt to create an account with the same username. When a new user attempts to create a new user account, I first check if it exists in the database using findOne which is an asynchronous call. Upon finishing finding one, there is a callback which calls another async call to a bcrypt subroutine.
I am scared of the following execution sequence:
req->req->findOne->findOne ...
or even:
req->req->findOne->bcrypt->findOne ...
How can I deal with such a situation?