Turns sync functions into Node.js-style async ones.
Inspired by node-asyncify.
var asyncify = { if typeof a !== "number" || typeof b !== "number" throw "add requires two numbers" return a + b} var add = console // Let’s do some math!// The sum is: 3// add requires two numbers
Installation
npm install simple-asyncify
var asyncify =
Usage
asyncify(syncFn)
Returns an async function that accepts the same arguments as syncFn
plus a
callback. It runs syncFn
with the arguments. If syncFn
throws an error, the
callback is invoked with that error. Otherwise the callback is invoked with
null
and the return value of syncFn
.
setImmediate
is used to make the function async.