Skip to content

Instantly share code, notes, and snippets.

@pragyandas
Created September 20, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pragyandas/14e26b1e85c2b9c22606f378ebaf3ee8 to your computer and use it in GitHub Desktop.
Save pragyandas/14e26b1e85c2b9c22606f378ebaf3ee8 to your computer and use it in GitHub Desktop.
partial application with promise created by pragyandas - https://repl.it/Ddl2/3
function bar(){
var args=[].slice.call(arguments);
var cb=args[args.length-1];
cb(null,"foo-bar");
}
var mapper={
foo:bar
}
function promisify(operator) {
return function() {
var args = [].slice.call(arguments);
return new Promise((resolve, reject)=>{
mapper[operator].apply(null, args.concat([(err, result)=>{
if (err) {
reject(err);
} else {
resolve(result);
}
}]));
});
};
}
var foo_promise=promisify("foo")();
foo_promise.then((res)=>console.log(res));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment