Skip to content

Instantly share code, notes, and snippets.

@developit
Forked from tec27/deferred.js
Last active July 9, 2016 18:19
Show Gist options
  • Save developit/dd5563ebfd863fcb29d7145b68884d1b to your computer and use it in GitHub Desktop.
Save developit/dd5563ebfd863fcb29d7145b68884d1b to your computer and use it in GitHub Desktop.
An extension of ES6 Promises that allows for easier deferred resolution/rejection
export class Deferred extends Promise {
constructor(executor) {
super( (resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
if (executor) executor(resolve, reject);
});
}
}
@tj
Copy link

tj commented Jul 9, 2016

looks like there's no access to this before super(), so this seems to be about as terse as you can go: https://github.com/tj/deferred.js/blob/master/index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment