Skip to content

Instantly share code, notes, and snippets.

@ukyo
Last active December 14, 2015 20:39
Show Gist options
  • Select an option

  • Save ukyo/5145740 to your computer and use it in GitHub Desktop.

Select an option

Save ukyo/5145740 to your computer and use it in GitHub Desktop.
http://www.slideshare.net/uupaa/flowjs のjQuery.Deferredの使い方はそもそもおかしい。
waitForAsyncProcesses().done(finishedCallback);
function waitForAsyncProcesses() {
var asyncFunc, A, B, C, D;
asyncFunc = function(ms) {
var dfd = $.Deferred();
setTimeout(dfd.resolve, ms);
return dfd.promise();
};
A = asyncFunc.bind(null, 10);
B = asyncFunc.bind(null, 100);
C = asyncFunc.bind(null, 20);
D = asyncFunc.bind(null, 200);
return $.when(
$.when(A(), B()),
$.when(C(), D())
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment