Last active
August 29, 2015 14:24
-
-
Save mgtitimoli/901bd6935acdfacd89a6 to your computer and use it in GitHub Desktop.
to-promise: convert given callback into a promise
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
"use strict"; | |
function toPromise(fn, ...args) { | |
// if fn throws an exception, this will reject | |
// the promise with what has been thrown | |
return new Promise(function(resolve) { | |
resolve(fn(...args)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment