Skip to content

Instantly share code, notes, and snippets.

@benjamingr
Last active August 19, 2016 03:06
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 benjamingr/a82abf6f5486c5ce88cd70cf892cfcd6 to your computer and use it in GitHub Desktop.
Save benjamingr/a82abf6f5486c5ce88cd70cf892cfcd6 to your computer and use it in GitHub Desktop.
function liquidate(obj, F = Promise.getNewLibraryCopy()) {
const promised = F.promisifyAll({__proto__: Object.create(obj)});
Object.assign(F.prototype, whenReadyAll.call(obj, promised)); // add the API
return promised;
function whenReadyAll(obj, target = {}) {
for(const prop in obj) target[prop] = (...args) => this.then(() => obj[prop](...args));
return target;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment