my-thunk
thunk a function what receive a callback
install
npm install mythunk-node
Usage
let mythunk = let asyncFunction // receive a few params, in general a callback like last param// but is not necessarylet argToAsyncFunction = 'some value'let thunk = // return a function// thunk is a function let { // err is the error generated by asyncFunction // res is the result from asyncFunction // this callback will catch this results} // 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