mythunk-node

0.1.1 • Public • Published

Build Status

my-thunk

thunk a function what receive a callback

install

npm install mythunk-node

Usage

let mythunk = require('mythunk-node')
let asyncFunction // receive a few params, in general a callback like last param
// but is not necessary
let argToAsyncFunction = 'some value'
let thunk = mythunk(asyncFunction,argToAsyncFunction) // return a function
// thunk is a function
 
let done = function (err, res) {
  // err is the error generated by asyncFunction
  // res is the result from asyncFunction
  // this callback will catch this results
}
 
thunk(done)  // exec now asyncFunction with the callback done passed
// return the value returned by asyncFunction
// if catch a error return the value returned by callback done, the error catched
// by thunk is passed to callback done

API

mythunk(thunkable[,paramsOfthunkable,...]) -> thunked

In general the thunkable receive like the last param a callback what is exec with err and other results.

thunked(callbackTothunkable)

Exec the thunkable and pass the callbackTothunkable like callback. If the callbackTothunkable is not given or is not a function a promise is returned.

callbackTothunkable([err,params,...])

if a error is catched by thunk is passed to callbackTothunkable

Package Sidebar

Install

npm i mythunk-node

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • cereceres