Guest User

Untitled

a guest
Jan 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. class Deferred {
  2. constructor(){
  3. this.canceled = false
  4. this.promise = new Promise((resolve, reject) => {
  5. this.resolve = (value) => {
  6. if(!this.canceled) resolve(value)
  7. }
  8. this.reject = (value) => {
  9. if(!this.canceled) reject(value)
  10. }
  11. })
  12. }
  13.  
  14. resolve(value){
  15. this.resolve(value)
  16. }
  17.  
  18. reject(value){
  19. this.reject(value)
  20. }
  21.  
  22. then(onFulfilled, onRejected){
  23. this.promise.then(onFulfilled, onRejected)
  24. }
  25.  
  26. cancel(){
  27. this.canceled = true
  28. }
  29. }
Add Comment
Please, Sign In to add comment