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

async-subscribe

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-subscribe

Emit events when you call an asynchronous function

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-20%
Maintainers
1
Weekly downloads
 
Created
Source

async subscribe

Emit lifecycle events from an asynchronous function call.

install

npm install async-subscribe

example

var subscribe = require('../');
var EE = require('events').EventEmitter;
var emitter = new EE();
var assert = require('assert');

emitter.on('myEvent', function (resp) {
    console.log('emits api event', resp);
});

emitter.on('asyncStart', function (args) {
    console.log('emits async start event');
    assert.deepEqual(args, { args: 'example' }, 'passes args to listener');
});

emitter.on('error', function (err) {
    console.log('emits error event', err);
});

function callAPI (opts, cb) {
    assert.deepEqual(opts, { args: 'example' },
        'should pass along args'
    );
    process.nextTick(cb.bind(null, null, { test: 'response' }));
}

function myCallback (err, resp) {
    console.log('calls my callback', err, resp);
}

var callAndEmit = subscribe(emitter, 'myEvent', callAPI);

// call this the same way as the original function, but now we emit
// events too
callAndEmit({ args: 'example' }, myCallback);

Keywords

FAQs

Package last updated on 21 Sep 2016

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