Created
October 11, 2016 22:44
-
-
Save Zodiase/bb3ead6d29d2d34b6db5bfe049442cc7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @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