{"id":19197336,"url":"https://github.com/versatica/awaitqueue","last_synced_at":"2025-08-22T00:32:33.603Z","repository":{"id":57187961,"uuid":"167402491","full_name":"versatica/awaitqueue","owner":"versatica","description":"JavaScript utility to enqueue async tasks for Node.js and the browser","archived":false,"fork":false,"pushed_at":"2024-05-13T12:34:23.000Z","size":536,"stargazers_count":31,"open_issues_count":0,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-13T13:55:04.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/versatica.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-24T16:49:15.000Z","updated_at":"2024-06-12T11:51:01.888Z","dependencies_parsed_at":"2023-02-01T08:15:34.962Z","dependency_job_id":"93a5138d-4f14-4713-9ef4-0d3c7ef273a8","html_url":"https://github.com/versatica/awaitqueue","commit_stats":{"total_commits":34,"total_committers":3,"mean_commits":"11.333333333333334","dds":0.08823529411764708,"last_synced_commit":"5eb6c8f027e645ba88fa8e29100001d5c68023a2"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2Fawaitqueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2Fawaitqueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2Fawaitqueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2Fawaitqueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/versatica","download_url":"https://codeload.github.com/versatica/awaitqueue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230542289,"owners_count":18242332,"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-09T12:16:24.466Z","updated_at":"2025-08-22T00:32:33.590Z","avatar_url":"https://github.com/versatica.png","language":"TypeScript","funding_links":["https://opencollective.com/mediasoup/"],"categories":[],"sub_categories":[],"readme":"# AwaitQueue\n\n[![][npm-shield-awaitqueue]][npm-awaitqueue]\n[![][github-actions-shield-awaitqueue]][github-actions-awaitqueue]\n[![][opencollective-shield-mediasoup]][opencollective-mediasoup]\n\nTypeScript utility to enqueue asynchronous tasks and run them sequentially one after another. For Node.js and the browser.\n\n## Installation\n\n```bash\nnpm install awaitqueue\n```\n\n## Usage\n\nIn ESM:\n\n```ts\nimport {\n\tAwaitQueue,\n\tAwaitQueueTask,\n\tAwaitQueueTaskDump,\n\tAwaitQueueStoppedError,\n\tAwaitQueueRemovedTaskError,\n} from 'awaitqueue';\n```\n\nUsing CommonJS:\n\n```ts\nconst {\n\tAwaitQueue,\n\tAwaitQueueTask,\n\tAwaitQueueTaskDump,\n\tAwaitQueueStoppedError,\n\tAwaitQueueRemovedTaskError,\n} = require('awaitqueue');\n```\n\n## Types\n\n### `type AwaitQueueTask`\n\n```ts\ntype AwaitQueueTask\u003cT\u003e = () =\u003e T | PromiseLike\u003cT\u003e;\n```\n\nTypeScript type representing a function that returns a value `T` or a Promise that resolves with `T`.\n\n### `type AwaitQueueTaskDump`\n\n```ts\ntype AwaitQueueTaskDump = {\n\tidx: number;\n\ttask: AwaitQueueTask\u003cunknown\u003e;\n\tname?: string;\n\tenqueuedTime: number;\n\texecutionTime: number;\n};\n```\n\nTypeScript type representing an item in the array returned by the `awaitQueue.dump()` method.\n\n- `idx`: Index of the pending task in the queue (0 means the task being processed now).\n- `task`: The function to be executed.\n- `name`: The name of the given `function` (if any) or the `name` argument given to `awaitQueue.push()` method (if any).\n- `enqueuedTime`: Time in milliseconds since the task was enqueued, this is, since `awaitQueue.push()` was called until its execution started or until now if not yet started.\n- `executionTime`: Time in milliseconds since the task execution started (or 0 if not yet started).\n\n## API\n\n### Class `AwaitQueue`\n\n```ts\nconst awaitQueue = new AwaitQueue();\n```\n\n#### Getter `awaitQueue.size`\n\n```ts\nsize: number;\n```\n\nNumber of enqueued pending tasks in the queue (including the running one if any).\n\n#### Method `awaitQueue.push()`\n\n```ts\nasync push\u003cT\u003e(task: AwaitQueueTask\u003cT\u003e, name?: string): Promise\u003cT\u003e\n```\n\nAccepts a task as argument and enqueues it after pending tasks. Once processed, the `push()` method resolves (or rejects) with the result (or error) returned by the given task.\n\n- `@param task`: Asynchronous or asynchronous function.\n- `@param name`: Optional task name (useful for `awaitQueue.dump()` method).\n\n#### Method `awaitQueue.stop()`\n\n```ts\nstop(): void\n```\n\nMakes all pending tasks reject with an instance of `AwaitQueueStoppedError`. The `AwaitQueue` instance is still usable for future tasks added via `push()` method.\n\n#### Method `awaitQueue.remove()`\n\n```ts\nremove(taskIdx: number): void\n```\n\nRemoves the pending task with given index. The task is rejected with an instance of `AwaitQueueRemovedTaskError`.\n\n- `@param taskIdx`: Index of the pending task to be removed.\n\n#### Method `awaitQueue.dump()`\n\n```ts\ndump(): AwaitQueueTaskDump[]\n```\n\nReturns an array with information about pending tasks in the queue. See the `AwaitQueueTaskDump` type above.\n\n### Class `AwaitQueueStoppedError`\n\nCustom `Error` derived class used to reject pending tasks once `awaitQueue.stop()` method has been called.\n\n### Class `AwaitQueueRemovedTaskError`\n\nCustom `Error` derived class used to reject pending tasks once `awaitQueue.remove()` method has been called.\n\n## Usage examples\n\nSee the [unit tests](src/tests/test.ts).\n\n## Author\n\n- Iñaki Baz Castillo [[website](https://inakibaz.me)|[github](https://github.com/ibc/)]\n\n## License\n\n[ISC](./LICENSE)\n\n[npm-shield-awaitqueue]: https://img.shields.io/npm/v/awaitqueue.svg\n[npm-awaitqueue]: https://npmjs.org/package/awaitqueue\n[github-actions-shield-awaitqueue]: https://github.com/versatica/awaitqueue/actions/workflows/awaitqueue.yaml/badge.svg\n[github-actions-awaitqueue]: https://github.com/versatica/awaitqueue/actions/workflows/awaitqueue.yaml\n[opencollective-shield-mediasoup]: https://img.shields.io/opencollective/all/mediasoup.svg\n[opencollective-mediasoup]: https://opencollective.com/mediasoup/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fversatica%2Fawaitqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fversatica%2Fawaitqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fversatica%2Fawaitqueue/lists"}