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

evented-async

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

evented-async

Event-driven extensions to the Node.js async library

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

evented-async

Event-based extensions for the Node.js async library

Installation

npm install evented-async

timer()

Instruments an async function so it emits timing values when the async callback is called.

Example

function task(taskDone) {
  setTimeout(taskDone, 1000);
}

emitter = new events.EventEmitter;
emitter.on('timeToRunTask', function(time) {
  console.log("Time to run task: " + time + "ms");
});

timedTask = eventedAsync.timer(emitter, 'timeToRunTask', task);
timedTask(function(){
  console.log("Timed task complete.")
});

profile()

Syntactic sugar for the timer function. profile will apply arguments to an async function and emit timing events, eliminating the need to pass a wrapper function to timer.

Example

function slowAdd(arg1, arg2, done) {
  setTimeout(function() {
    done(arg1 + arg2);
  }, 1000);
}

emitter = new events.EventEmitter
emitter.on('timeToSlowAdd', function(time, result) {
  console.log("Time to calculate 5 + 6 = " + result + ": " + time + "ms");
});

eventedAsync.profile(emitter, 'timeToSlowAdd', slowAdd, 5, 6);

Queue class

An event-driven wrapper for async.queue. There are two major differences in semantics:

  • The push and unshift methods take a standard comma-separated list of arguments, rather than an object that maps argument names to argument values. These methods do not accept callbacks, nor do they support adding multiple tasks at once.
  • The queue emits events for the 'saturated', 'empty', and 'drain' callbacks.

Example

q = new eventedAsync.Queue(function(message, done){
  setTimeout(function(){
    console.log("New message: " + message);
    done();
  }, 1000);
});

q.on('drain', function(){
  console.log("All queued messages have been written.");
});

q.push("Hello...");
q.push("World!");

Keywords

FAQs

Package last updated on 08 Jul 2013

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