Skip to content

Instantly share code, notes, and snippets.

@jimmed
Last active December 30, 2015 01:18
Show Gist options
  • Save jimmed/7754850 to your computer and use it in GitHub Desktop.
Save jimmed/7754850 to your computer and use it in GitHub Desktop.
Converting Promises
var someTask = $.Deferred();
doSomethingAsync(function(result) {
someTask.resolve(result);
});
return someTask.promise();
// becomes
var someTask = Promise.defer();
doSomethingAsync(function(result) {
someTask.resolve(result);
});
return someTask.promise;
// Or, better yet,
return Promise.promisify(doSomethingAsync)(/* any parameters here */)
$.when.apply($, someArrayOfPromises).then(function(set, of, variables) { ... })
// becomes
Promise.all(someArrayOfPromises).spread(function(set, of variables) { ... });
Promise.join(set, of, promises).spread(function(set, of, results) { ... });
Promise.all(...).then(function(arrayOfResults) { })
Promise.props({
profile: FS.API.get('Spihnx'),
somethingElse: FS.API.get('awesome')
}).then(function(result) {
console.log(result.profile);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment