Here is a question about what I would think would be a simple pattern in node js.
Here is my example in coffeescript:
db_is_open = false
db.open ->
db_is_open = true
wait = ->
wait() until db_is_open
And here again in javascript:
var db_is_open = false;
db.open(function() {
db_is_open = true;
});
function wait() {};
while (not db_is_open) { wait()};
This does not work at all because the while loop never relinquishes control, which I guess makes sense. However how can I tell the wait function to try the next callback in the queue?
Why are you waiting, and not just using a callback that runs inside of the function passed to
db.open? This is pretty much idiomatic Node code:Basically, you should simply follow the patterns laid out in the documentation.