项目作者: bevry

项目描述 :
Emit events in serial or parallel with support for synchronous and asynchronous listeners
高级语言: JavaScript
项目地址: git://github.com/bevry/event-emitter-grouped.git
创建时间: 2013-07-12T16:27:00Z
项目社区:https://github.com/bevry/event-emitter-grouped

开源协议:Other

下载


Event Emitter Grouped

Status of the GitHub Workflow: bevry
NPM version
NPM downloads


GitHub Sponsors donate button
ThanksDev donate button
Patreon donate button
Liberapay donate button
Buy Me A Coffee donate button
Open Collective donate button
crypto donate button
PayPal donate button


Discord server badge
Twitch community badge

Emit events in serial or parallel with support for synchronous and asynchronous listeners

Usage

Complete API Documentation.

  1. // Importer
  2. var EventEmitterGrouped = require('event-emitter-grouped')
  3. // Instantiate a new instance
  4. var emitter = new EventEmitterGrouped()
  5. // Bind an asynchronous event
  6. emitter.on('hello', function (next) {
  7. console.log('\tasync started')
  8. setTimeout(function () {
  9. console.log('\tasync finished')
  10. next()
  11. }, 1000)
  12. })
  13. // Bind a synchronous event
  14. emitter.on('hello', function () {
  15. console.log('\tsync started and finished')
  16. })
  17. // Bind a prioritized event
  18. function vipListener() {
  19. console.log('\tvip started and finished')
  20. }
  21. vipListener.priority = 1
  22. emitter.on('hello', vipListener)
  23. // Emit the events in serial (one after the other in a waiting fashion)
  24. console.log('hello in serial started')
  25. emitter.emitSerial('hello', function (err) {
  26. console.log('hello in serial finished')
  27. // Emit the events in parallel (all at once)
  28. console.log('hello in parallel started')
  29. emitter.emitParallel('hello', function (err) {
  30. console.log('hello in parallel finished')
  31. })
  32. })
  33. /* Outputs:
  34. hello in serial started
  35. vip started and finished
  36. async started
  37. async finished
  38. sync started and finished
  39. hello in serial finished
  40. hello in parallel started
  41. vip started and finished
  42. async started
  43. sync started and finished
  44. async finished
  45. hello in parallel finished
  46. */

Install

npm

  • Install: npm install --save event-emitter-grouped
  • Import: import * as pkg from ('event-emitter-grouped')
  • Require: const pkg = require('event-emitter-grouped')

jspm

  1. <script type="module">
  2. import * as pkg from '//dev.jspm.io/event-emitter-grouped@6.7.0'
  3. </script>

Editions

This package is published with the following editions:

  • event-emitter-grouped aliases event-emitter-grouped/index.cjs which uses the Editions Autoloader to automatically select the correct edition for the consumer’s environment
  • event-emitter-grouped/source/index.js is ESNext source code for Node.js 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules
  • event-emitter-grouped/edition-browsers/index.js is ESNext compiled for web browsers with Require for modules
  • event-emitter-grouped/edition-node-4/index.js is ESNext compiled for Node.js 4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules

TypeScript

This project provides its type information via inline JSDoc Comments. To make use of this in TypeScript, set your maxNodeModuleJsDepth compiler option to 5 or thereabouts. You can accomplish this via your tsconfig.json file like so:

  1. {
  2. "compilerOptions": {
  3. "maxNodeModuleJsDepth": 5
  4. }
  5. }

History

Discover the release history by heading on over to the HISTORY.md file.

Backers

Code

Discover how to contribute via the CONTRIBUTING.md file.

Authors

Maintainers

Contributors

Finances

GitHub Sponsors donate button
ThanksDev donate button
Patreon donate button
Liberapay donate button
Buy Me A Coffee donate button
Open Collective donate button
crypto donate button
PayPal donate button

Sponsors

  • Andrew Nesbitt — Software engineer and researcher
  • Balsa — We’re Balsa, and we’re building tools for builders.
  • Codecov — Empower developers with tools to improve code quality and testing.
  • Poonacha Medappa
  • Rob Morris
  • Sentry — Real-time crash reporting for your web apps, mobile apps, and games.
  • Syntax — Syntax Podcast

Donors

License

Unless stated otherwise all works are:

and licensed under: