New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

callbackmaybe

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

callbackmaybe

I just met you / and this is crazy / but here's a module / CallbackMaybe

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

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

node-callbackmaybe

A module that makes it easy to support both event emitters and callbacks in your node.js API methods.

Build Status

Usage


var CallbackMaybe = require('callbackmaybe');

YourModule.prototype.someMethod(param, callback) {

  var cbm = new CallbackMaybe(callback, options);

  anEmittingFunction().on('foo', function(foo) {
    cbm.write('Do something with ' + foo);
  }).on('end', function() {
    cbm.end();
  }).on('error', function(err) {
    cbm.error(err);
  });

  return(cbm);

};


In the above example, if someMethod is passed a callback, the callback will be invoked with an array of the items written via cbm.write(). The callback will be invoked with an error if cbm.error() is called.

With or without a callback, an EventEmitter is returned which will emit a data event for each item written and an end event with a count of items emitted. An error event is emitted if cbm.error() is called.

A method implemented as above will support the following access methods:


yourModule.someMethod(function(err, results) {
  // an array of results or an error
});

yourModule.someMethod().on('data', function(data) {
  // each result, one at a time
});

yourModule.someMethod().on('end', function(count) {
  // An easy way to get a count of results
});

You can present the same interface options even if you only have access to an array internally:


YourModule.prototype.anotherMethod(param, callback) {

  var cbm = new CallbackMaybe(callback, options);

  aListFunction(function(results) {
    cbm.write(results);
    cbm.end();
  });

  return(cbm);

};

anotherMethod will have the same access methods as someMethod above.

Currently only one option is supported:

  • limit - the maximum number of items to emit or pass to the callback. Calls to write after the limit is reached will return false.

Install

  npm install callbackmaybe

Dependencies

This library has no production dependencies, only the following test dependencies:

Keywords

FAQs

Package last updated on 26 Aug 2012

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