{"id":23764462,"url":"https://github.com/chaqchase/async-sequence","last_synced_at":"2025-09-05T08:33:33.920Z","repository":{"id":188072576,"uuid":"678082994","full_name":"chaqchase/async-sequence","owner":"chaqchase","description":"async-sequence contains a utility class to run sequential promises in Typescript","archived":false,"fork":false,"pushed_at":"2023-11-23T00:38:16.000Z","size":1195,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-29T00:24:37.478Z","etag":null,"topics":["async","bun","nodejs","promise","promise-library","sequencer"],"latest_commit_sha":null,"homepage":"","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/chaqchase.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,"governance":null}},"created_at":"2023-08-13T16:17:08.000Z","updated_at":"2023-11-23T00:34:39.000Z","dependencies_parsed_at":"2023-11-23T01:39:25.445Z","dependency_job_id":"286d647c-b32d-4802-a9bf-0a86cc70a6c0","html_url":"https://github.com/chaqchase/async-sequence","commit_stats":null,"previous_names":["triyanox/async-sequence","chaqchase/async-sequence"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaqchase%2Fasync-sequence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaqchase%2Fasync-sequence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaqchase%2Fasync-sequence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaqchase%2Fasync-sequence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chaqchase","download_url":"https://codeload.github.com/chaqchase/async-sequence/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232032239,"owners_count":18462988,"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","bun","nodejs","promise","promise-library","sequencer"],"created_at":"2024-12-31T22:18:14.505Z","updated_at":"2024-12-31T22:18:16.318Z","avatar_url":"https://github.com/chaqchase.png","language":"TypeScript","readme":"# async-sequence\n\n**async-sequence** contains **PromiseSequencer** a utility class that enables you to execute promises sequentially with concurrency and retry capabilities. It empowers you to manage promise execution order, concurrency, and handles retries and logging seamlessly.\n\n## Installation\n\nInstall **async-sequence** using your preferred package manager:\n\n```bash\n# Using npm\nnpm install @triyanox/async-sequence\n\n# Using Bun\nbun add @triyanox/async-sequence\n\n# Using Yarn\nyarn add @triyanox/async-sequence\n\n# Using PNPM\npnpm add @triyanox/async-sequence\n\n```\n\n## Usage\n\n```ts\nimport createPromiseSequencer from '@triyanox/async-sequence';\n\n// Example usage\nconst promiseSequencer = createPromiseSequencer(\n  // add your promises here\n  [() =\u003e Promise.resolve('foo'), () =\u003e Promise.reject('bar')],\n  {\n    // the maximum number of promises that can run at the same time\n    concurrency: 2,\n    // the maximum number of times a task can be retried\n    retryAttempts: 3,\n    // the delay between retries\n    retryDelay: 1000,\n    // a logger that logs the status of the PromiseSequencer\n    logger: {\n      log: (level, message) =\u003e {\n        console.log(`[${level.toUpperCase()}] ${message}`);\n      },\n    },\n    // callbacks for when a task is completed, failed or retried\n    onTaskCompleted: (result) =\u003e {\n      console.log(`Task completed with result: ${result()}`);\n    },\n    onTaskFailed: (error) =\u003e {\n      console.log(`Task failed with error: ${error()}`);\n    },\n    onTaskRetried: (task) =\u003e {\n      console.log(`Task retried: ${task}`);\n    },\n    // whether to disable logs\n    disableLogs: false,\n  },\n);\n\n// use a custom generator\nconst promiseSequencer = createPromiseSequencer(\n  (function* custom() {\n    yield () =\u003e Promise.resolve('foo');\n    yield () =\u003e Promise.resolve('bar');\n    yield () =\u003e Promise.reject(new Error('baz'));\n  })(),\n);\n\n// start the PromiseSequencer\npromiseSequencer.start();\n\n// get the sequencer results\nconst results = await promiseSequencer.getResults();\n\n// stop the PromiseSequencer\npromiseSequencer.stop();\n```\n\n## API\n\n### Enum: LogLevel\n\nRepresents different log levels for logging messages.\n\n- `ERROR`: Error log level.\n- `INFO`: Information log level.\n- `DEBUG`: Debug log level.\n\n### Interface: Logger\n\nA logger interface to implement custom logging behavior.\n\n- `log(level: LogLevel, message: string): void`: Logs a message at the specified log level.\n\n### Interface: PromiseSequencerOptions\\\u003cT\u003e\n\nOptions for configuring the PromiseSequencer.\n\n- `promiseGenerator`: A generator that yields promises.\n- `concurrency` (optional): The number of promises to run concurrently. Default: 1.\n- `retryAttempts` (optional): The number of times to retry a failed task. Default: 0.\n- `retryDelay` (optional): The delay in milliseconds between retries. Default: 0.\n- `logger` (optional): A logger instance for custom logging. Default: console.\n- `disableLogs` (optional): Whether to disable logging. Default: false.\n- `onTaskCompleted` (optional): A callback for task completion.\n- `onTaskFailed` (optional): A callback for task failure.\n- `onTaskRetried` (optional): A callback for task retries.\n- `throwOnErrors` (optional): Whether to throw an error when a task fails. Default: false.\n\n### Class: PromiseSequencer\\\u003cT\u003e\n\nA class for executing promises sequentially with concurrency and retry capabilities.\n\n- `constructor(options: PromiseSequencerOptions\u003cT\u003e)`: Creates a new PromiseSequencer instance.\n- `start(): Promise\u003cboolean\u003e`: Starts executing promises.\n- `stop()`: Stops the PromiseSequencer.\n- `getQueue(): (() =\u003e Promise\u003cT\u003e)[]`: Returns the current queue of tasks.\n- `getRunningTasks(): (() =\u003e Promise\u003cT\u003e)[]`: Returns the current running tasks.\n- `getCompletedTasks(): (() =\u003e Promise\u003cT\u003e)[]`: Returns the completed tasks.\n- `getFailedTasks(): (() =\u003e Promise\u003cT\u003e)[]`: Returns the failed tasks.\n- `getRetryTasks(): (() =\u003e Promise\u003cT\u003e)[]`: Returns the tasks that are currently being retried.\n- `getResults(): Promise\u003cT[]\u003e`: Returns the results of the PromiseSequencer if the `throwOnErrors` option is set to `false` it will return null for the failed tasks if not it will throw an error.\n- `setCurrentConcurrency(concurrency: number): void`: Sets the current concurrency.\n\n### Function: createPromiseSequencer\\\u003cT\u003e\n\nCreates a new PromiseSequencer instance.\n\n- `promiseGenerator`: A generator that yields promises.\n- `options` (optional): Options for configuring the PromiseSequencer.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaqchase%2Fasync-sequence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaqchase%2Fasync-sequence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaqchase%2Fasync-sequence/lists"}