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

promise-breaker

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-breaker

Library to help write libraries that accept both promises and callbacks.

  • 5.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
816K
increased by2.58%
Maintainers
1
Weekly downloads
 
Created

What is promise-breaker?

The promise-breaker npm package provides utilities for converting between callback-based functions and promise-based functions. It allows you to easily work with both styles of asynchronous code.

What are promise-breaker's main functionalities?

Callback to Promise

This feature allows you to convert a callback-based function into a promise-based function. The example demonstrates converting a simple callback function that adds two numbers into a promise-based function.

const promiseBreaker = require('promise-breaker');

function callbackFunction(arg1, arg2, callback) {
  setTimeout(() => {
    callback(null, arg1 + arg2);
  }, 1000);
}

const promiseFunction = promiseBreaker.promisify(callbackFunction);

promiseFunction(1, 2).then(result => {
  console.log(result); // 3
}).catch(err => {
  console.error(err);
});

Promise to Callback

This feature allows you to convert a promise-based function into a callback-based function. The example demonstrates converting a simple promise function that adds two numbers into a callback-based function.

const promiseBreaker = require('promise-breaker');

function promiseFunction(arg1, arg2) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(arg1 + arg2);
    }, 1000);
  });
}

const callbackFunction = promiseBreaker.callbackify(promiseFunction);

callbackFunction(1, 2, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    console.log(result); // 3
  }
});

Other packages similar to promise-breaker

Keywords

FAQs

Package last updated on 25 Jun 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