Skip to content

Instantly share code, notes, and snippets.

@Zodiase
Created October 11, 2016 22:44
Show Gist options
  • Save Zodiase/bb3ead6d29d2d34b6db5bfe049442cc7 to your computer and use it in GitHub Desktop.
Save Zodiase/bb3ead6d29d2d34b6db5bfe049442cc7 to your computer and use it in GitHub Desktop.
/**
* @param {function} func - The function to call. The payload of the promise.
* @param {Array.<*>} args - The list of arguments for `func`.
* @param {*} ctx - The context for `func`.
*/
function makePromise(func, args, ctx) {
return new Promise(function (resolve, reject) {
try {
func.apply(ctx, Array.prototype.concat.call(args, function (err, result) {
if (err) { reject(err); } else { resolve(result); }
}));
} catch (err) {
reject(err);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment