deferredPromise.js

Home   »   deferredPromise.js

const createDeferredPromise = () => {
  let ret = { isPending: true, isFulfilled: false, isRejected: false }
  ret.promise = new Promise((res, rej) => {
    ret.resolve = (...args) => {
      ret.isPending = false
      ret.isFulfilled = true
      res(...args)
    }
    ret.reject = (...args) => {
      ret.isPending = false
      ret.isRejected = true
      rej(...args)
    }
  })
  return ret
}

Leave a Reply

Your email address will not be published. Required fields are marked *