Last active
December 30, 2015 01:18
-
-
Save jimmed/7754850 to your computer and use it in GitHub Desktop.
Converting Promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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