{"id":18879710,"url":"https://github.com/loilo/node-event-emitting-promise","last_synced_at":"2026-02-20T04:30:19.346Z","repository":{"id":57231254,"uuid":"90138945","full_name":"loilo/node-event-emitting-promise","owner":"loilo","description":"An extended Promise object implementing Node's EventEmitter methods","archived":false,"fork":false,"pushed_at":"2017-05-04T07:07:51.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T19:02:03.944Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/loilo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-03T10:52:37.000Z","updated_at":"2017-05-03T10:53:12.000Z","dependencies_parsed_at":"2022-09-14T07:50:31.337Z","dependency_job_id":null,"html_url":"https://github.com/loilo/node-event-emitting-promise","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fnode-event-emitting-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fnode-event-emitting-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fnode-event-emitting-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fnode-event-emitting-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loilo","download_url":"https://codeload.github.com/loilo/node-event-emitting-promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239841742,"owners_count":19705981,"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":[],"created_at":"2024-11-08T06:38:54.558Z","updated_at":"2026-02-20T04:30:17.280Z","avatar_url":"https://github.com/loilo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# event-emitting-promise\n\nAn extended [Promise](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise) object implementing Node's [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) methods\n\n## Reasoning\nFrom time to time, I found myself in the need to combine the comfortable program flow that Promises offer (especially with `async`/`await`) with the verbose usefulness of events.\n\nMy usual use case is the creation of CLI versions from functions I've wrote. Using this package, that can be done pretty easily.\n\n## Install\n```bash\n# With yarn\nyarn add event-emitting-promise\n\n# With npm\nnpm install --save event-emitting-promise\n```\n\n## Usage\nLet's say we want to create a programmatic and a CLI version of a function called `myFunc()`.\n\nConsider this the `my-func.js`:\n```javascript\nconst EventEmittingPromise = require('event-emitting-promise')\n\n// Asynchronous partial tasks\nconst { task1, task2, task3 } = require('./somewhere')\n\nmodule.exports = function myFunc () {\n  // The EventEmittingPromise constructor callback takes an\n  // additional argument called \"emit\", which is the\n  // EventEmitter.prototype.emit method.\n  return new EventEmittingPromise(async (resolve, reject, emit) =\u003e {\n    try {\n      const result1 = await task1()\n      emit('partial', 'task1', result1)\n\n      const result2 = await task2()\n      emit('partial', 'task2', result2)\n\n      const result3 = await task3()\n      emit('partial', 'task3', result3)\n\n      resolve({\n        task1: result1,\n        task2: result2,\n        task3: result3\n      })\n    } catch (err) {\n      reject(err)\n    }\n  })\n}\n```\n\nAnd this the `my-func-cli.js`:\n```javascript\nconst myFunc = require('./my-func')\n\nmodule.exports = function myFuncCLI () {\n  return myFunc()\n    // The created Promise provides all of the EventEmitter methods\n    // (except emit) and allows chaining them.\n    .on('partial', (name, result) =\u003e {\n      console.log(\n        `Partial task ${name} has finished with result:`,\n        result\n      )\n    })\n    .then(() =\u003e {\n      console.log('Done.')\n    })\n    .catch(err =\u003e {\n      console.error('An error occurred:', err)\n    })  \n}\n```\n\nThat way, places calling `myFunc()` can easily be informed about the progress of the function call.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floilo%2Fnode-event-emitting-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floilo%2Fnode-event-emitting-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floilo%2Fnode-event-emitting-promise/lists"}