Created
July 4, 2013 16:16
-
-
Save felixvisee/5928890 to your computer and use it in GitHub Desktop.
promisify functions with `successCallback`/`errorCallback` arguments using https://github.com/slightlyoff/Promises
This file contains 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
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); | |
}); |
This file contains 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
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