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

@ctheory/promisify

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ctheory/promisify

Promisify callback based functions

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

@ctheory/promisify npm (scoped) npm type definitions

A simple TS typed function for promisifying callback based functions.

Usage

async/await syntax
import promisify from '@ctheory/promisify';

const callbackFunction = (arg1, arg2, callback) => {
  if (arg1 && arg2) {
    callback(null, 'Success');
  } else {
    callback(new Error('An error happened'));
  }
};

const promisedFunction = promisify(callbackFunction);

try {
  const result = await promisedFunction('arg1', 'arg2');
  // Use result as usual
} catch (err) {
  // Callbacks are assumed to use error first convention
  // The error will be thrown if present
  console.log('callbackFunction failed with an error', err);
}
Promise syntax
const promisedFunction = promisify(callbackFunction);

promisedFunction
  .then(result => {
    // Use the result
  })
  .catch(err => {
    // Handle the thrown error
  });

FAQs

Package last updated on 01 Jan 2019

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