You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

call-me-maybe

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

call-me-maybe

Let your JS API users either give you a callback or receive a promise

1.0.2
next
latest
Source
npm
Version published
Weekly downloads
7.1M
-9.9%
Maintainers
1
Weekly downloads
 
Created

What is call-me-maybe?

The 'call-me-maybe' npm package is designed to handle callbacks and promises in a unified way. It allows developers to write functions that can return a promise if no callback is provided, or execute a callback if one is given. This flexibility makes it easier to work with asynchronous code in JavaScript.

What are call-me-maybe's main functionalities?

Handling callbacks and promises

This feature allows a function to handle both callbacks and promises. If a callback is provided, it is called with the result; otherwise, a promise is returned. The code sample demonstrates how to implement a simple asynchronous operation that can be used either way.

const maybe = require('call-me-maybe');

function asyncOperation(callback) {
  return maybe(callback, new Promise((resolve, reject) => {
    setTimeout(() => resolve('Done!'), 1000);
  }));
}

// Using with callback
asyncOperation(result => console.log(result));

// Using as a promise
asyncOperation().then(result => console.log(result));

Other packages similar to call-me-maybe

Keywords

promise

FAQs

Package last updated on 31 Oct 2022

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