Have ideas to improve npm?Join in the discussion! »

    cancelp

    0.1.0 • Public • Published

    cancelp

    | a cancelable promise

    usage

    import cancelp from 'cancelp'
     
    const promise = cancelp((resolve, reject) => {
      setTimeout(
        () => resolve('Hello'),
        100
      )
    })
     
    promise.catch(e => {
      console.log(e)
      // => 'hello, you are stopped now'
    })
     
    promise.then(() => {
      // this never runs
    })
     
    promise.cancel('Hello, you are stopped now')

    Instead of calling cancel you can also call cancelReject or cancelResolve. These act like you would expect, resolving/rejecting the values you pass to them immediately

    Keywords

    none

    Install

    npm i cancelp

    DownloadsWeekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • avatar