{"id":17921810,"url":"https://github.com/3axap4ehko/asygen","last_synced_at":"2025-03-24T02:31:59.639Z","repository":{"id":144719686,"uuid":"616512780","full_name":"3axap4eHko/asygen","owner":"3axap4eHko","description":"0-Deps, simple and fast async generator library for browser and NodeJS.","archived":false,"fork":false,"pushed_at":"2024-10-24T00:21:21.000Z","size":1661,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-24T14:27:22.326Z","etag":null,"topics":["async","browser","deferred","generator","node","npm","promise"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/3axap4eHko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["3axap4eHko","zource-dev"],"patreon":"zource","custom":["https://paypal.me/3axap4eHko"]}},"created_at":"2023-03-20T14:31:39.000Z","updated_at":"2024-10-24T00:21:24.000Z","dependencies_parsed_at":"2023-10-17T05:46:51.209Z","dependency_job_id":"444b9d0e-4aa2-45f3-8f36-ee84dde05793","html_url":"https://github.com/3axap4eHko/asygen","commit_stats":{"total_commits":310,"total_committers":2,"mean_commits":155.0,"dds":"0.12903225806451613","last_synced_commit":"73c43ac5b3e4e9c29a503147e82173eadb8d0488"},"previous_names":[],"tags_count":266,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3axap4eHko%2Fasygen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3axap4eHko%2Fasygen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3axap4eHko%2Fasygen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3axap4eHko%2Fasygen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3axap4eHko","download_url":"https://codeload.github.com/3axap4eHko/asygen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221931684,"owners_count":16903794,"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","browser","deferred","generator","node","npm","promise"],"created_at":"2024-10-28T20:36:13.912Z","updated_at":"2024-10-28T20:36:14.607Z","avatar_url":"https://github.com/3axap4eHko.png","language":"TypeScript","funding_links":["https://github.com/sponsors/3axap4eHko","https://github.com/sponsors/zource-dev","https://patreon.com/zource","https://paypal.me/3axap4eHko"],"categories":[],"sub_categories":[],"readme":"# Asygen\n\n0-Deps, simple and fast async generator library for browser and NodeJS.\n\nSupports ESM and CommonJS modules.\n\n[![Build Status][github-image]][github-url]\n[![NPM version][npm-image]][npm-url]\n[![Downloads][downloads-image]][npm-url]\n[![Coverage Status][codecov-image]][codecov-url]\n[![Maintainability][codeclimate-image]][codeclimate-url]\n\n## Installation\n\nNpm installation\n\n```bash\nnpm install asygen\n```\n\nYarn installation\n\n```bash\nyarn add asygen\n```\n\n## Utilities\n\n#### Deferred\n\n- Represents a deferred operation.\n- Provides methods resolve and reject to control the wrapped promise.\n- Exposes properties promise and status to get the underlying promise and its current status.\n\n#### Queue\n\n- A queue system for handling asynchronous tasks.\n- Offers methods `push`, `pull`, and `done` to manage tasks.\n\n#### Generatorify\n\n- Convert a task into an asynchronous iterable.\n- The iterable can be used in `for await...of` loops to process values as they're produced.\n\n#### Combine\n\n- Combine multiple asynchronous iterables into a single iterable.\n- The resulting iterable will yield values from all input iterables and complete when all of them are done.\n\n## Usage\n\n#### Create deferred operation\n\n```typescript\nimport { defer, Status } from 'asygen';\n\nconst deferred = defer\u003cnumber\u003e();\nconsole.log(deferred.status); // Status.PENDING\n\ndeferred.resolve(42);\ndeferred.promise.then((value) =\u003e {\n  console.log(value); // 42\n  console.log(deferred.status); // Status.RESOLVED\n});\n```\n\n#### Create a deferred operation from events\n\n```typescript\nimport { defer } from 'asygen';\n\nconst result = defer();\n\nconsole.log(result.status); // pending\n\ntask.once('data', error.resolve);\ntask.once('error', error.reject);\nawait result.promise;\n\nconsole.log(result.status); // resolved or rejected\n```\n\n#### Task queue\n\n```typescript\nimport { createQueue } from 'asygen';\n\nconst queue = createQueue\u003cnumber\u003e();\n\nqueue.push(1);\nqueue.push(2);\nqueue.push(3);\n\nqueue.pull().promise.then((value) =\u003e console.log(value)); // 1\nqueue.pull().promise.then((value) =\u003e console.log(value)); // 2\n```\n\n#### Generatorify\n\n```typescript\nimport { generatorify } from 'asygen';\n\nconst task = async (callback) =\u003e {\n  await callback('Hello');\n  await callback('World');\n  return 'Done!';\n};\n\nconst iterable = generatorify(task);\n\n(async () =\u003e {\n  for await (const value of iterable) {\n    console.log(value); // \"Hello\", then \"World\"\n  }\n})();\n```\n\n#### Convert events to asyncGenerator\n\n```typescript\nimport { once } from 'node:events';\nimport { generatorify, Task } from 'asygen';\n\n// send data from the event until process exit\nconst task: Task = async (send) =\u003e {\n  process.on('data', send);\n  await once(process, 'exit');\n};\n\nfor await (const data of generatorify(task)) {\n  // handle data\n}\n```\n\n#### Combine tasks\n\n```typescript\nimport { generatorify, combine } from 'asygen';\n\nconst task1 = async (callback) =\u003e {\n  await callback('Task1 - Hello');\n  await callback('Task1 - World');\n};\n\nconst task2 = async (callback) =\u003e {\n  await callback('Task2 - Foo');\n  await callback('Task2 - Bar');\n};\n\nconst iterable1 = generatorify(task1);\nconst iterable2 = generatorify(task2);\n\nconst combined = combine(iterable1, iterable2);\n\n(async () =\u003e {\n  for await (const value of combined) {\n    console.log(value); // Logs values from both task1 and task2\n  }\n})();\n```\n\n#### Combine generators\n\n```typescript\nimport { combine } from 'asygen';\n\nconst sleep = (timeout: number) =\u003e\n  new Promise((resolve) =\u003e setTimeout(resolve, timeout));\n\nasync function* generate(timeout: number, count: number) {\n  for (let index = 0; index \u003c count; index++) {\n    yield index;\n    await sleep(timeout);\n  }\n}\n\nfor await (const data of combine(generate(100, 5), generate(500, 2))) {\n  // handle data\n}\n// First:    0 1 2 3 4 -\n// Second:   0 . . . . 1\n// Combined: 0 0 1 2 3 4 1\n```\n\n## License\n\nLicense [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)\nCopyright (c) 2023-present Ivan Zakharchanka\n\n[npm-url]: https://www.npmjs.com/package/asygen\n[downloads-image]: https://img.shields.io/npm/dw/asygen.svg?maxAge=43200\n[npm-image]: https://img.shields.io/npm/v/asygen.svg?maxAge=43200\n[github-url]: https://github.com/3axap4eHko/asygen/actions/workflows/cicd.yml\n[github-image]: https://github.com/3axap4eHko/asygen/actions/workflows/cicd.yml/badge.svg\n[codecov-url]: https://codecov.io/gh/3axap4eHko/asygen\n[codecov-image]: https://codecov.io/gh/3axap4eHko/asygen/branch/master/graph/badge.svg?token=ZKYSDY7GQ0\n[codeclimate-url]: https://codeclimate.com/github/3axap4eHko/asygen/maintainability\n[codeclimate-image]: https://api.codeclimate.com/v1/badges/0f24a357154bada2a37f/maintainability\n[snyk-url]: https://snyk.io/test/npm/asygen/latest\n[snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/3axap4eHko/asygen.svg?maxAge=43200\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3axap4ehko%2Fasygen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3axap4ehko%2Fasygen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3axap4ehko%2Fasygen/lists"}