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

event-to-promise

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-to-promise

Create a promise waiting for an event

  • 0.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
63K
increased by30.63%
Maintainers
1
Weekly downloads
 
Created
Source

event-to-promise

Build Status Dependency Status devDependency Status

Create a promise waiting for an event

Install

Download manually or with package-manager.

npm
npm install --save event-to-promise

Example

var eventToPromise = require('event-to-promise');

var createServer = function (port) {
  var server = require('http').createServer();
  server.listen(port);

  // The server will be returned once it has started listening.
  //
  // If an error happened, it will be forwarded instead.
  return eventToPromise(server, 'listening').then(function () {
    return server;
  });
};

// Using plain promise.
createServer(80).then(function (server) {
  console.log('Server listening on http://localhost:80/');
}).catch(function (error) {
  console.error('Server could not start:', error);
});

// Even better using generators!
require('bluebird').coroutine(function *() {
  try {
    var server = yield createServer(80);
    console.log('Server listening on http://localhost:80/');
  } catch (error) {
    console.error('Server could not start:', error);
  }
})();

Contributing

Contributions are very welcome, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet

Keywords

FAQs

Package last updated on 22 May 2014

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