@freckle/cancelable-promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@freckle/cancelabe-promise

Utilities to create a promise that can be canceled.

Install

yarn add @freckle/cancelable-promise

Versioning and release process

See RELEASE.md.

Usage

const expensiveOperation = () => fetchData().then(parse).then(transform)

const Component = () => {
  const [result, setResult] = setState(null)
  useEffect(() => {
    const promise = makeCancelable(expensiveOperation).then(res => {
      setResult(res)
    })
    return () => {
      // Cancel on cleanup
      promise.cancel()
    }
  })

  return result
}

LICENSE

Readme

Keywords

none

Package Sidebar

Install

npm i @freckle/cancelable-promise

Weekly Downloads

504

Version

1.0.0

License

MIT

Unpacked Size

2.22 MB

Total Files

24

Last publish

Collaborators

  • luckysoni
  • z0isch
  • stackptr
  • carlos-cubas
  • freckle-engineering