Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Callback when all scripts have finished Loading? #2

Open
jonnyreeves opened this issue Feb 9, 2012 · 4 comments
Open

Global Callback when all scripts have finished Loading? #2

jonnyreeves opened this issue Feb 9, 2012 · 4 comments

Comments

@jonnyreeves
Copy link

I'm looking for a way to get a global callback when all of my scripts have finished loading asynchronously, is this possible?

@berklee
Copy link
Owner

berklee commented Feb 10, 2012

There is a global callback after a timeout, but I'm guessing that's not what you want. You could always monitor nbl.q to see if all scripts have loaded, or define a callback function for every script that checks nbl.q? I'll put it on the list for the next version, thanks!

Just to be sure, how are you using NBL, perhaps I can come up with a solution in the meantime?

@jonnyreeves
Copy link
Author

Heya, thanks for replying. I was using NBL to load our app's js libraries at runtime; however, once all libraries had finished loading I needed to execute one last chunk of code to kick the whole thing off. At first I was using a sequence similar to this:

nbl.l([ 'script1.js', 'script2.js', 'script3.js', onAllScriptsLoaded ]);

However the onAllScriptsLoaded callback was being fired after script3.js completed which lead to a race condition. What I was really looking for was a way to say "once all these scripts have finished, execute this callback", perhaps the syntax could look something like this:

nbl.l([ 'script1.js', 'script2.js', 'script3.js' ]).onAllComplete(function () { console.log('all scripts loaded!') });

I'm afraid I had to switch to LAB.js because of this missing feature, however, my first choice was NBL due to its compact size (I need to inline the code into my project's bootstrap).

@berklee
Copy link
Owner

berklee commented Feb 11, 2012

I get it, it' a fair point. I haven't run into this issue myself, but in retrospect, I don't understand why I did not put in that feature in the first place! This is going to the top of the list, thanks. Would you like me to contact you when I've fixed this?

@jonnyreeves
Copy link
Author

Yes please; although if I get some free time I will have a stab at writing the code in a fork :)

Thanks for your hard work on this library and your swift replies.
Jonny.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants