Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a-callback

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-callback

An utility to convert node callbacks to promise

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

a-callback

A utility to convert node callbacks to promise

fromCallback

fromCallback(
    resolver: (cb: (error?: any, ...args: any[]) => any) => any,
    [Object {multiArgs: boolean=false} options]
) -> Promise
fromNode(
    resolver: (cb: (error?: any, ...args: any[]) => any) => any,
    [Object {multiArgs: boolean=false} options]
) -> Promise

Returns a promise that is resolved by a node style callback function. This is the most fitting way to do on the fly promisification when libraries don't expose classes for automatic promisification by undefined.

The resolver function is passed a callback that expects to be called back according to error-first node conventions.

Setting multiArgs to true means the resulting promise will always fulfill with an array of the callback's success value(s). This is needed because promises only support a single success value while some callback API's have multiple success value. The default is to ignore all but the first success value of a callback function.

Using manual resolver:

import util from 'util';
import {fromCallback} from 'a-callback';
// "email-templates" doesn't expose prototypes for promisification
const emailTemplates = util.promisify(require('email-templates'));
const templatesDir = path.join(__dirname, 'templates');

const template = await emailTemplates(templatesDir);
const [html, text] = await fromCallback(cb => template('newsletter', cb), {multiArgs: true});
console.log(html, text);

Keywords

FAQs

Package last updated on 06 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc