Closed bryanwb closed 13 years ago
Either your example code is missing something or you're misunderstanding how async functions work.
In your example, the users.get
callback is the last thing executed. Everything is synchronous blocking code (users.save should have a callback btw) So sys.puts(name)
is executed before name = doc.name
.
The best way to understand it is to put console.debug()
statements all throughout your code and see what order things actually happen.
Also you should have a callback on users.save and not call users.get till after the callback has come back. If not you have a race condition and it will only work under certain conditions. Trust me, these are really nasty to track down.
For more about how to chain async functions see my Step library. Or simply nest callbacks.
hmm, I must be doing this wrong. Sorry for the trouble
no trouble at all, let me know if you figure it out.
I am trying to access the document properties with a closure variable
it does work if I do this
why is this?