{"id":17110641,"url":"https://github.com/gerkindev/sequential-event","last_synced_at":"2025-07-24T17:31:04.963Z","repository":{"id":98923948,"uuid":"98181162","full_name":"GerkinDev/sequential-event","owner":"GerkinDev","description":"An event emitter that supports promises for sequential execution of handlers","archived":false,"fork":false,"pushed_at":"2018-08-31T19:12:45.000Z","size":1729,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-27T00:24:52.626Z","etag":null,"topics":["eventemitter","javascript","promise"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GerkinDev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-24T10:57:40.000Z","updated_at":"2019-12-12T01:58:15.000Z","dependencies_parsed_at":"2023-06-11T03:23:01.392Z","dependency_job_id":null,"html_url":"https://github.com/GerkinDev/sequential-event","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GerkinDev%2Fsequential-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GerkinDev%2Fsequential-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GerkinDev%2Fsequential-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GerkinDev%2Fsequential-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GerkinDev","download_url":"https://codeload.github.com/GerkinDev/sequential-event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227463847,"owners_count":17778465,"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":["eventemitter","javascript","promise"],"created_at":"2024-10-14T16:27:37.186Z","updated_at":"2024-12-01T01:06:24.506Z","avatar_url":"https://github.com/GerkinDev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sequential-event\n\nCode checks:\n[![Build Status](https://travis-ci.org/GerkinDev/sequential-event.svg?branch=master)](https://travis-ci.org/GerkinDev/sequential-event)\n[![Maintainability](https://api.codeclimate.com/v1/badges/6f730e6f07635b7a57ad/maintainability)](https://codeclimate.com/github/GerkinDev/sequential-event/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/6f730e6f07635b7a57ad/test_coverage)](https://codeclimate.com/github/GerkinDev/sequential-event/test_coverage)\n\nPackage infos:\n[![npm](https://img.shields.io/npm/dm/sequential-event.svg)](https://npmjs.org/package/sequential-event)\n[![npm version](https://badge.fury.io/js/sequential-event.svg)](https://badge.fury.io/js/sequential-event)\n[![license](https://img.shields.io/github/license/GerkinDev/sequential-event.svg)](https://github.com/GerkinDev/sequential-event)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![Greenkeeper badge](https://badges.greenkeeper.io/GerkinDev/sequential-event.svg)](https://greenkeeper.io/)\n\n\u003e **See the API documentation on [github.io/sequential-event](https://gerkindev.github.io/sequential-event/)**\n\nThis library is a variation of standard event emitters. Handlers are executed\nsequentialy, and may return **Promises** if it executes asynchronous code.\n\nFor usage in the browser, use the files in the `dist` directory\n\n## Example usage\n\n```javascript\nconst SequentialEvent = require( 'sequential-event' );\n\nfunction sampleTime( startTime ) {\n    return new Date().getTime() - startTime;\n}\nconst eventEmitter = new SequentialEvent();\n\n// We create a new array with a new timer\neventEmitter.on( 'retime', startTime =\u003e {\n    return [ sampleTime( startTime ) ];\n});\n// We wait 100ms and we re-time\neventEmitter.on( 'retime', ( startTime, timers ) =\u003e {\n    // This operation is async, so we return a Promise that will be resolved\n    // with the timers array\n    return new Promise(( resolve ) =\u003e {\n        setTimeout(() =\u003e {\n            timers.push( sampleTime( startTime ));\n            return resolve( timers );\n        }, 100 );\n    });\n});\n// We re-take a sample immediatly\neventEmitter.on( 'retime', ( startTime, timers ) =\u003e {\n    // This operation is sync, so we can return our timers array directly\n    timers.push( sampleTime( startTime ));\n    return timers;\n});\n\neventEmitter\n    // Emit our retime event with the current date\n    .emit( 'retime', new Date().getTime())\n    // Log normaly if everything is OK, or log with error\n    .then( timers =\u003e console.log( timers ))\n    .catch( err =\u003e console.error( err ));\n```\n\nHere is an example of output of this code:\n\n\u003e [ 1, 109, 109 ]\n\nYou can see that each `on` handlers are executed sequentially, after the end of\nthe previous handler.\n\n## API\n\n### emit\n\nTriggers all listeners of the provided events, spraying `params` to each\ncallbacks. Returned or resolved values from callbacks (if returning a\n`Promise`) are passed as last parameter of the next callback function.\n\nSignature:\n\n\u003e emit(*string* `eventName`[, *...any* `params`]) =\u003e *Promise(any)*\n\n### off\n\nRemove callbacks from events.\n\nSignature:\n\n\u003e off(*object* `events` ) =\u003e *this*\n\n```\n// Remove all listeners\neventListener.off();\n// Remove all listeners on 'eventFoo'\neventListener.off( 'eventFoo' );\n// Remove `cb` from 'eventFoo'\neventListener.off( 'eventFoo', cb );\n// Remove `cbFoo` from 'event1' and `cbBar` from 'event2'\neventListener.off({\n    event1: cbFoo,\n    event2: cbBar,\n});\n```\n\n### once\n\nBind callbacks to specified events. The callback will be executable a single\ntime for each event.\n\nSignatures:\n\n\u003e once(*string* `eventName`, *function* `callback`) =\u003e *this*\n\u003e\n\u003e once(*object* `events` ) =\u003e *this*\n\n```\n// Attach the same callback to `event1` \u0026 `event2`. `event1` callback may be\n// executed a single time, as `event2`.\neventListener.once( 'event1 event2', () =\u003e Promise.resolve( 'foo' ));\n// Bind a callback that returns 'foo' on `event1`, and 'bar' on `event2`. Both\n// will be run a single time.\neventListener.once({\n    event1: () =\u003e Promise.resolve( 'foo' ),\n    event2: () =\u003e Promise.resolve( 'bar' ),\n});\n```\n\n### on\n\nAttach callbacks to specified events.\n\nSignatures:\n\n\u003e on(*string* `eventName`, *function* `callback`) =\u003e *this*\n\u003e\n\u003e on(*object* `events` ) =\u003e *this*\n\n```\n// Attach the same callback to `event1` \u0026 `event2`\neventListener.on( 'event1 event2', () =\u003e Promise.resolve( 'foo' ));\n// Bind a callback that returns 'foo' on `event1`, and 'bar' on `event2`\neventListener.off({\n    event1: () =\u003e Promise.resolve( 'foo' ),\n    event2: () =\u003e Promise.resolve( 'bar' ),\n});\n```\n\n## Compatibility\n\nThis package can run on:\n\n* Node `\u003e=` 6.0.0\n* Most modern browsers\n\n### NPM scripts\n\n - `npm t`: Run test suite\n - `npm start`: Run `npm run build` in watch mode\n - `npm run test:watch`: Run test suite in [interactive watch mode](http://facebook.github.io/jest/docs/cli.html#watch)\n - `npm run test:prod`: Run linting and generate coverage\n - `npm run build`: Generate bundles and typings, create docs\n - `npm run lint`: Lints code\n - `npm run commit`: Commit using conventional commit style ([husky](https://github.com/typicode/husky) will tell you to use it if you haven't :wink:)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgerkindev%2Fsequential-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgerkindev%2Fsequential-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgerkindev%2Fsequential-event/lists"}