Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create all of your promises that you know you need up-front. Build a <code>.when</code> with them. Save the promise returned from the <code>.when</code>. As you add new events, which require new promises, add new <code>.when</code>s, using the promise from previous <code>.when</code>s, plus whatever new promises you've completed.</p> <p>Your application will have multiple <code>single points of failure</code>, if you're using the final <code>.when</code> as your "Go ahead with the app.". IE: if any one promise fails at any point, then any <code>.when</code> created after that is also going to fail.</p> <p>...but if that's your intent, or you've got some solid error-handling, it should do you.</p> <p>I'm trying to keep this library-agnostic -- usually, I use my own implementation, which is half-way between something jQuery does, and something that Crockford did in a recent talk, but if we assume that:</p> <p>functions return promise-handlers<br> "when" returns a promise-handler promise-handlers have at least a <code>.done</code> and <code>.fail</code> -- or accept two arguments, or whatever and whatever happens inside of a function will control whether the promise is <code>rejected/resolved</code> or <code>kept/broken</code> (or whatever), then you might end up with a bunch of functionality that looks like:</p> <pre><code>var doing = doSomething(), // returns promise making = makeSomething(), // returns promise loading = loadSomething(), // returns promise dependencies_lvl_1 = when(doing, making, loading); </code></pre> <p>Later on, you might add a new module or widget -- maybe it saves some work:</p> <pre><code>var saving = saveSomething(), //returns promise dependencies_lvl_2 = when(dependencies_lvl_1, saving); </code></pre> <p>Maybe after that, you need to switch pages, but you need your data to cache first</p> <pre><code>var caching = cacheData(), // returns promise when(dependencies_lvl_2, caching) .done(goToNextPage) .fail(handleError); </code></pre> <p>If you look at it, you know for a fact that as long as <code>when</code> returns a promise which only succeeds if all promises are kept (and when all promises are kept), and none of them broke, then <code>dependencies_lvl_2</code> there, includes all dependencies from <code>dependencies_lvl_1</code>, plus additional promises.</p> <p>The level-3 <code>.when</code>, then, has a resolution depending on every single thing which has been added to the chain.</p> <p>And as long as you keep caching your promises into variables (or some sort of future-access), you can keep chaining these together, into eternity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload