Socket
Book a DemoInstallSign in
Socket

@simmo/task

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@simmo/task

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

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

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

Keywords

async

FAQs

Package last updated on 13 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts