Socket
Socket
Sign inDemoInstall

esync

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    esync

Dirt simple solution to async event listeners


Version published
Weekly downloads
9
increased by125%
Maintainers
1
Install size
4.48 kB
Created
Weekly downloads
 

Readme

Source

ESync is a dirt simple module for waiting on a bunch of async tasks. Build Status

var esync = require('esync');

var wait = esync();

wait(function(cb) {
    cb();
});
wait(function(cb) {
    setTimeout(cb, 1000);
});
wait(function(cb) {
    var err = new Error("Oops!");
    cb(err);
});

wait.end(function(err) {
    /* ... */
});

Its main purpose is as a utility for EventEmitters that need to offer listeners a way to delay execution.

var esync = require('esync');
var EventEmitter = require('events');

var emitter = new EventEmitter();

emitter.on('foo', function(arg1, arg2, wait) { wait(function(cb) {
    setTimeout(cb, 1000);
}); });

var wait = esync();
emitter.emit('foo', 3, 5, wait);
wait.end(function(err) {
    /* ... */
});

The beaty of this is that it's optional; listeners can simply ignore the parameter. Additionally, it follows the ‘error first’ callback parameter convention seen in Node.js.

Keywords

FAQs

Last updated on 09 Apr 2015

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc