@simmo/task

0.0.1 • Public • Published

Task

Travis npm downloads License

JavaScript utility that provides a consistent, clean return from promises. Particularly helpful when using await/async.

Install

NPM

npm install @simmo/task

Yarn

yarn add @simmo/task

Usage

task(<Promise>) => { error: <Any>, data: <Any> }

task always returns an object. The object will contain two properties; error and data.

If the promise is resolved, error will be null and data will contain anything the promise has returned. If the promise is rejected, error will return the error provided by the promise and data will be null.

import task from '@simmo/task'

const { error, data } = await task(fetch('/some-api'))

if (error) {
  // Failure
  console.error(error)
} else {
  // Success
  console.log(data)
}

License

MIT © Mike Simmonds

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    6
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    6
  • 0.0.0
    0

Package Sidebar

Install

npm i @simmo/task

Weekly Downloads

6

Version

0.0.1

License

MIT

Unpacked Size

4.46 kB

Total Files

4

Last publish

Collaborators

  • simmo