Skip to content

Instantly share code, notes, and snippets.

@mgtitimoli
Last active August 29, 2015 14:24
Show Gist options
  • Save mgtitimoli/901bd6935acdfacd89a6 to your computer and use it in GitHub Desktop.
Save mgtitimoli/901bd6935acdfacd89a6 to your computer and use it in GitHub Desktop.
to-promise: convert given callback into a promise
"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