1.1.0 • Published 3 years ago

handle-async v1.1.0

Weekly downloads
105
License
MIT
Repository
github
Last release
3 years ago

handle-async NPM version Downloads Build Status

Resolves any function to a value. Generators, callbacks, promises, flat values - don't worry about it!

Pass in any function, and we'll make sure you get the value how you need it.

Install

npm install handle-async --save

Example

Assume these input functions for the following examples:

// good ol' function that returns a value
const flat = () => 123

// calling a callback with the value
const cb = (cb) => cb(null, 123)

// creating an async function that resolves the value
const asyncd = async () => 123

// a function that returns a promise with the resolved value
const promised = () => new Promise((reject, resolve ) => resolve(123))

Callbacks

import { callbackify } from 'handle-async'

callbackify(flat, (err, res) => console.log(res)) // 123
callbackify(cb, (err, res) => console.log(res)) // 123
callbackify(asyncd, (err, res) => console.log(res)) // 123
callbackify(promised, (err, res) => console.log(res)) // 123

Promises

Same thing, but returning promises so you can use async await.

import { promisify } from 'handle-async'

console.log(await promisify(flat)) // 123
console.log(await promisify(cb)) // 123
console.log(await promisify(asyncd)) // 123
console.log(await promisify(promised)) // 123

Same code, way different functions. Nice and easy.

1.1.0

3 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago