Socket
Socket
Sign inDemoInstall

call-me-maybe

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

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


Version published
Weekly downloads
5.6M
decreased by-15.85%
Maintainers
1
Created
Weekly downloads
 

Package description

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

Readme

Source

call-me-maybe Continuous Release

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

Usage

var maybe = require("call-me-maybe")

module.exports = function asyncFunc (cb) {
  return maybe(cb, new Promise(function(resolve, reject) {
    // ...
  }))
}

API

maybe(cb, promise)

If the callback cb is truthy, returns undefined and will call cb when promise is settled. The parameters passed to cb are standard error-first:

  • If promise is fulfilled, then it is called with the result of the promise: cb(null, result)
  • If promise is rejected, then it is called with the rejection error: cb(err)

If cb is falsey, then promise is returned.

Keywords

FAQs

Last updated on 31 Oct 2022

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc