@alexbinary/callbackify

2.0.2Β β€’Β PublicΒ β€’Β Published

callbackify

Naive callbackification πŸ™ˆ

npm GitHub release Build Status dependencies Status devDependencies Status

WARNING: This is a very basic implementation that works in simple cases but will probably break in more advanced situations.

Install

Install using npm or yarn :

$ npm install @alexbinary/callbackify
# or
$ yarn add @alexbinary/callbackify

Usage

let callbackify = require('@alexbinary/callbackify')

function f () { return Promise.resolve('ok') }

callbackify(f)((err, result) => {
  if (err) console.error(err)
  else console.log(result)  // 'ok'
})

Documentation

let callbackify = require('@alexbinary/callbackify')

callbackify(function)

Returns a function that forwards all its arguments to function and takes a callback as last argument.

function is expected to return a Promise. If the promise rejects then the callback is called with the error as first argument. If the promise resolves then the callback is called with null as first argument and then all the resolved arguments (node callback style).

Note that the returned function can still be used with a Promise style.

This method is idempotent, i.e. if function is the result of calling callbackify then the returned value is function itself. This is done by defining a Symbol property on the returned object and checking for that property before processing.

callbackify(object, methods)

Replaces methods in given object whose names are listed in methods by the result of callbackify(method).

Returns object.

Licence

MIT

/@alexbinary/callbackify/

    Package Sidebar

    Install

    npm i @alexbinary/callbackify

    Weekly Downloads

    7

    Version

    2.0.2

    License

    MIT

    Last publish

    Collaborators

    • alexbinary