promise2thunk
v1.0.1
Published
Convert (transform) promise to thunk, just like was in co@3
Downloads
28
Readme
promise2thunk
Convert (transform) promise to thunk, just like was in co@3
Install
npm i promise2thunk --save
npm test
Usage
For more use-cases see the tests
var promise2thunk = require('promise2thunk')
var parseJson = require('then-parse-json')
var promise = parseJson('{"foo":"bar"}')
var thunk = promise2thunk(promise)
thunk(function (err, res) {
console.log(err) //=> null
console.log(res) //=> { foo: 'bar' }
})
Related
- always-promise: Create Bluebird Promise from given async or synchronous function. It automatically convert sync functions to async, then to promise.
- always-callback: Create callback api for given sync function. Guarantee that given function (sync or async, no matter) will always have callback api and will handle errors correctly.
- make-callback: Make synchronous function to support callback api
- handle-callback: Initial step for creating hybrid APIs, used by
hybridify
. Handle callback in promise - give promise and callback return promise. - handle-arguments: Handles given Arguments object - return separatly last argument (commonly callback) and other arguments as Array. Useful in node-style callback flow.
- manage-arguments: Prevents arguments leakage - managing arguments. From Optimization killers by Petka Antonov.
- is-async-function: Check that given function is async (callback) function or not. Trying to guess that based on check if
callback
orcb
exists in function arguments. - is-es6-generators: Check whether a value is a
Generator
orGeneratorFunction
. Theco
way, more strict checking. Always return boolean true or false, never null or undefined.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.