Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Deferred {
- constructor(){
- this.canceled = false
- this.promise = new Promise((resolve, reject) => {
- this.resolve = (value) => {
- if(!this.canceled) resolve(value)
- }
- this.reject = (value) => {
- if(!this.canceled) reject(value)
- }
- })
- }
- resolve(value){
- this.resolve(value)
- }
- reject(value){
- this.reject(value)
- }
- then(onFulfilled, onRejected){
- this.promise.then(onFulfilled, onRejected)
- }
- cancel(){
- this.canceled = true
- }
- }
Add Comment
Please, Sign In to add comment