Skip to content

Instantly share code, notes, and snippets.

@modernserf
Forked from getify/ex1.js
Last active August 29, 2015 14:00
Show Gist options
  • Save modernserf/11149833 to your computer and use it in GitHub Desktop.
Save modernserf/11149833 to your computer and use it in GitHub Desktop.
// using asynquence+iterable sequences
var domready;
ASQ()
// wait for `domready` before we proceed
.seq( domready = ASQ.iterable() )
.gate(
requestJSON( "foo.json" ),
requestJSON( "bar.json" )
)
.val( transformJSONs )
.seq( uploadJSON )
.seq( displayRecords )
.or( handleError );
$(document).ready( domready.next );
// using native promises
var domReady = new Promise($);
domReady.then(function (){
return Promise.all([
requestJSON( "foo.json" ),
requestJSON( "bar.json" )
]);
}).then(transformJSONs)
.then(uploadJSON)
.then(displayRecords)
.catch(handleError);
// see http://jsfiddle.net/modernserf/TyuPA/2/ for working code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment