On May 18, 2014, at 16:20, Michael DeMond wrote:

> Total Node newb here. :)  I just started a few weeks ago and have been 
> learning it.

Welcome!

> I am curious if there is an equivalent to a window.onload event handler in 
> NodeJS.  Essentially, I am looking to execute a delegate when all of the code 
> in my NodeJS application has loaded.

window.onload is an invention of web browsers, which gets called when the DOM 
has been processed and all external resources including scripts, stylesheets 
and images have been loaded. Node is not a browser so it doesn't have most of 
those concepts so there is no equivalent to window.onload in node.

Code that does things asynchronously (which is the norm in node) should be 
calling a callback when it's finished. So if you want to do something when that 
asynchronous code is done, you do it in the callback.

It can get a bit complicated when you have multiple things you need to do and 
wait for them all to complete. There are control flow libraries that can help 
you manage the complexity; async is a popular one, but there are others. You 
don't need to use a library, of course; you could do something as simple as 
keep a counter of how many tasks you've started, then decrement the counter 
after each task completes; when the counter reaches 0, all tasks have been 
completed and you can do whatever you wanted to do next.



-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/72D0A492-C0A5-40A1-A611-0EA29FDAE503%40ryandesign.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to