You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
DOCUMENT: Load array of scripts in series then fire callback
DOCUMENT: Load array of scripts in parallel then fire callback
Even if it's just "use async" with a quick snippet.
Many competing script loaders have a call signature like loadScript([script1, script2, script3, ...], callback). I don't think it's necessary to add to little-loader, but it means people are used to having a way to achieve that. (I personally don't like the at-a-glance ambiguity over whether calling with an array loads them in series or parallel, without consulting docs).
functionswornLoad(resource,syncCB,context){returnnewPromise(function(fulfill,reject){_lload(resource,function(err){varres;if(typeofsyncCB==='function')try{res=syncCB.call(context,err);}catch(e){reject(e)}if(err){reject(err);// no-op if syncCB threw}else{fulfill(res);}});})}
It allows to use promises for parallel loading while giving the opportunity to run code synchronoulsy on load.
Edit: From then on you can use Promise.all() for parallel loading, and
swornLoad('foo').then(function(){returnswornLoad('bar')}).then(function(){// do your thing})
for sequential loading.
Both approaches can be trivially combined.
If you have a better name for the promisified _lload, I'm all ears, I don't like swornLoad much.
The text was updated successfully, but these errors were encountered: