{"id":30580374,"url":"https://github.com/borewit/async-queue","last_synced_at":"2025-09-13T22:29:16.274Z","repository":{"id":276320047,"uuid":"928926543","full_name":"Borewit/async-queue","owner":"Borewit","description":"Converts events to an async iterable queue","archived":false,"fork":false,"pushed_at":"2025-05-26T06:34:03.000Z","size":133,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-21T00:05:55.632Z","etag":null,"topics":[],"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/Borewit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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},"funding":{"github":"Borewit","buy_me_a_coffee":"borewit"}},"created_at":"2025-02-07T13:48:09.000Z","updated_at":"2025-04-18T20:56:55.000Z","dependencies_parsed_at":"2025-02-07T15:37:08.347Z","dependency_job_id":null,"html_url":"https://github.com/Borewit/async-queue","commit_stats":null,"previous_names":["borewit/await-queue","borewit/async-queue"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Borewit/async-queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fasync-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fasync-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fasync-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fasync-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Borewit","download_url":"https://codeload.github.com/Borewit/async-queue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fasync-queue/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272634558,"owners_count":24967669,"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","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-08-29T05:23:26.086Z","updated_at":"2025-08-29T05:23:27.277Z","avatar_url":"https://github.com/Borewit.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Borewit","https://buymeacoffee.com/borewit"],"categories":[],"sub_categories":[],"readme":"[![Node.js CI](https://github.com/Borewit/await-queue/actions/workflows/ci.yml/badge.svg)](https://github.com/Borewit/await-queue/actions/workflows/ci.yml)\n[![NPM version](https://badge.fury.io/js/@borewit%2Fasync-queue.svg)](https://npmjs.org/package/@borewit/async-queue)\n[![npm downloads](http://img.shields.io/npm/dm/@borewit/async-queue.svg)](https://npmcharts.com/compare/@borewit/async-queue?start=356)\n\n# @borewit/async-queue\n\n`await-queue` is a lightweight, generic, and type-safe asynchronous queue implemented in TypeScript. It allows you to enqueue items and retrieve them one at a time using promises, making it ideal for processing events, messages, or tasks in a first-in-first-out (FIFO) order. This is especially handy when reading asynchronous items received via events.\n\n## Features\n\n- **Generic \u0026 Type-Safe:** Write once and use with any type (e.g., string, number, object).\n- **FIFO Order:** Processes items in the order they were received.\n- **Promise-Based:** Retrieve items asynchronously using promises.\n- **Event Integration:** Perfect for handling asynchronous events like user actions, network messages, or other event-driven data.\n\n## Installation\n\nInstall `@borewit/async-queue` from npm:\n\n```bash\nnpm install @borewit/async-queue\n```\n\n## Usage\nBelow is an example of how to add and read string messages to/from the queue. This example simulates asynchronous events (using setTimeout) that push string messages into the queue:\n\n```ts\nimport { AsyncQueue } from '@borewit/async-queue';\n\n// Create a new queue for string messages\nconst queue = new AsyncQueue\u003cstring\u003e();\n\n// Example: Simulate incoming messages via asynchronous events\nfunction simulateIncomingMessages() {\n  setTimeout(() =\u003e queue.push(\"Hello\"), 1000);\n  setTimeout(() =\u003e queue.push(\"World\"), 2000);\n  setTimeout(() =\u003e queue.push(\"From AsyncQueue!\"), 3000);\n}\n\nsimulateIncomingMessages();\n\n// Process messages asynchronously, one at a time\nasync function processMessages() {\n  while (true) {\n    const message = await queue.next();\n    console.log(\"Received message:\", message);\n    // Add additional processing logic here...\n  }\n}\n\nprocessMessages();\n```\nIn this example, the queue is used to collect string messages that are simulated to arrive at different times. The asynchronous loop in processMessages waits for each message, ensuring they are handled in FIFO order.\n\n\n## API\n\n```ts\npush(item: T): void\n```\nAdds an item to the queue.\n\n- Parameters\n  -  `item: T` - The item to add.\n\nIf there are pending consumers waiting for an item (via `next(`)),\nthe promise is immediately resolved with the new item.\n\n```ts\nnext(): Promise\u003cT\u003e\n```\nReturns a promise that resolves with the next item in the queue.\n- Returns:\n  - `Promise\u003cT\u003e` - A promise that resolves to the next item.\n\nIf the queue already contains an item, the promise resolves immediately;\notherwise, it waits until an item is pushed.\n\n## When to Use This Queue\n\nThis queue is particularly useful when you need to process asynchronous events in a controlled, sequential manner. Instead of handling events directly as they arrive, you can push them into the queue and then process them one by one. This approach is beneficial in scenarios such as:\n\n* Handling user input events.\n* Processing network messages.\n* Managing asynchronous tasks or jobs in order.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE file](LICENSE.txt) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborewit%2Fasync-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborewit%2Fasync-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborewit%2Fasync-queue/lists"}