handle-async
Resolves any function to a value. Generators, callbacks, promises, flat values - don't worry about it!
Last updated 3 years ago by contra .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install handle-async 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 1.0.2                                ...           latest (3 years ago)

3 Versions

  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (16)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |