npm

Bring the best of OSS JavaScript development to your projects with npm Orgs - private packages & team management tools.Learn more »

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

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability