Skip to content

Instantly share code, notes, and snippets.

@felixvisee
Created July 4, 2013 16:16
Show Gist options
  • Save felixvisee/5928890 to your computer and use it in GitHub Desktop.
Save felixvisee/5928890 to your computer and use it in GitHub Desktop.
promisify functions with `successCallback`/`errorCallback` arguments using https://github.com/slightlyoff/Promises
var service = ...; // webinos file api service
promisify(service.requestFileSystem, service)(null, null)
.then(function (filesystem) {
return filesystem.root;
})
.then(function (root) {
return promisify(root.getFile, root)("test", { create : true });
})
.then(function (file) {
console.log(file.name);
});
function promisify(fun, thisArg) {
return function () {
var argsArray = Array.prototype.slice.call(arguments);
return new Promise(function (resolver) {
argsArray.push(resolver.fulfill.bind(resolver));
argsArray.push(resolver.reject.bind(resolver));
fun.apply(thisArg, argsArray);
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment