{"id":13550523,"url":"https://github.com/imcuttle/node-await-event-emitter","last_synced_at":"2025-04-14T03:25:29.751Z","repository":{"id":38362001,"uuid":"118327948","full_name":"imcuttle/node-await-event-emitter","owner":"imcuttle","description":"await events library like EventEmitter","archived":false,"fork":false,"pushed_at":"2023-08-23T23:42:07.000Z","size":1580,"stargazers_count":21,"open_issues_count":19,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T00:03:41.344Z","etag":null,"topics":["async","await","event-emitter","events","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imcuttle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-21T11:18:41.000Z","updated_at":"2023-12-28T00:25:04.000Z","dependencies_parsed_at":"2024-01-15T20:50:46.743Z","dependency_job_id":"fffbc922-69ae-4c59-8f37-c7180ee60253","html_url":"https://github.com/imcuttle/node-await-event-emitter","commit_stats":{"total_commits":10,"total_committers":3,"mean_commits":"3.3333333333333335","dds":0.4,"last_synced_commit":"b96233d732093cd7357f84e6ac90e9629db83ac5"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fnode-await-event-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fnode-await-event-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fnode-await-event-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fnode-await-event-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imcuttle","download_url":"https://codeload.github.com/imcuttle/node-await-event-emitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248814631,"owners_count":21165797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","await","event-emitter","events","nodejs"],"created_at":"2024-08-01T12:01:34.310Z","updated_at":"2025-04-14T03:25:29.720Z","avatar_url":"https://github.com/imcuttle.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","JavaScript"],"sub_categories":[],"readme":"# await-event-emitter\n\n**Note: node-await-event-emitter is just implements the series processing, If you need parallel case, Please use the package [tapable](https://www.npmjs.com/package/tapable) which is used by webpack.**\n\nAwait events library like EventEmitter\n\n[![build status](https://img.shields.io/travis/imcuttle/node-await-event-emitter/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/node-await-event-emitter)\n[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/node-await-event-emitter.svg?style=flat-square)](https://codecov.io/github/imcuttle/node-await-event-emitter?branch=master)\n[![NPM version](https://img.shields.io/npm/v/await-event-emitter.svg?style=flat-square)](https://www.npmjs.com/package/await-event-emitter)\n[![NPM Downloads](https://img.shields.io/npm/dm/await-event-emitter.svg?style=flat-square\u0026maxAge=43200)](https://www.npmjs.com/package/await-event-emitter)\n\n## Why?\n\nThe concept of Webpack plugin has lots of lifecycle hooks, they implement this via EventEmitter.\nIn the primitive [events](https://nodejs.org/dist/latest/docs/api/events.html) module on nodejs, the usage as follows\n\n```javascript\nconst EventEmitter = require('events')\nconst emitter = new EventEmitter()\n\nemitter\n  .on('event', () =\u003e {\n    // do something *synchronously*\n  })\n  .emit('event', '...arguments')\n```\n\nThe listener must be **synchronous**, that is way i wrote it.  \nAnd await-event-emitter support synchronous emitter magically :smile:\n\n## Installation\n\n```bash\nnpm install --save await-event-emitter\n```\n\n## Usage\n\n```javascript\nconst AwaitEventEmitter = require('await-event-emitter').default\n\nconst emitter = new AwaitEventEmitter()\nconst tick = () =\u003e\n  new Promise((resolve) =\u003e {\n    setTimeout(() =\u003e {\n      console.log('tick')\n      resolve()\n    }, 1000)\n  })\n\nemitter.on('event', async () =\u003e {\n  // wait to print\n  await tick()\n})\n\nasync function run() {\n  // NOTE: it's important to `await` the reset process\n  await emitter.emit('event', '...arguments')\n  await emitter.emit('event', 'again')\n\n  // support emit it synchronously\n  emitter.emitSync('event', 'again')\n}\n\nrun()\n```\n\n## API\n\n### Class `AwaitEventEmitter`\n\n- `addListener(event, listener)` : AwaitEventEmitter  \n  alias: `on`\n- `once(event, listener)`\n- `prependListener(event, listener)` : AwaitEventEmitter  \n  alias: `prepend`\n- `prependOnceListener(event, listener)` : AwaitEventEmitter  \n  alias: `prependOnce`\n- `removeListener(event, listener)` : AwaitEventEmitter  \n  alias: `off`\n- `listeners(event)` : []\n- `emit(event, ...args)` : Promise.resolve(boolean)  \n  emit listeners asynchronously, we recommended await it resolved the result\n- `emitSync(event, ...args)` : boolean\n  emit listeners synchronously\n\n## Test\n\n```bash\nnpm test\n```\n\n## Contributing\n\n- Fork it!\n- Create your new branch:  \n  `git checkout -b feature-new` or `git checkout -b fix-which-bug`\n- Start your magic work now\n- Make sure npm test passes\n- Commit your changes:  \n  `git commit -am 'feat: some description (close #123)'` or `git commit -am 'fix: some description (fix #123)'`\n- Push to the branch: `git push`\n- Submit a pull request :)\n\n## Authors\n\nThis library is written and maintained by imcuttle, \u003ca href=\"mailto:imcuttle@163.com\"\u003eimcuttle@163.com\u003c/a\u003e.\n\n## License\n\nMIT - [imcuttle](https://github.com/imcuttle) 🐟\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Fnode-await-event-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimcuttle%2Fnode-await-event-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Fnode-await-event-emitter/lists"}