{"id":21766583,"url":"https://github.com/damianc/hot-generator","last_synced_at":"2025-06-13T13:08:14.050Z","repository":{"id":57266780,"uuid":"196888237","full_name":"damianc/hot-generator","owner":"damianc","description":"Allows making the hot generators","archived":false,"fork":false,"pushed_at":"2020-04-05T09:17:36.000Z","size":12,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-13T13:08:05.236Z","etag":null,"topics":["es6","generator","generator-functions","hot-generators","javascript","sharing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/damianc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-14T22:11:50.000Z","updated_at":"2020-04-05T09:17:39.000Z","dependencies_parsed_at":"2022-08-25T03:41:17.633Z","dependency_job_id":null,"html_url":"https://github.com/damianc/hot-generator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/damianc/hot-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianc%2Fhot-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianc%2Fhot-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianc%2Fhot-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianc%2Fhot-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damianc","download_url":"https://codeload.github.com/damianc/hot-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damianc%2Fhot-generator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259650959,"owners_count":22890385,"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":["es6","generator","generator-functions","hot-generators","javascript","sharing"],"created_at":"2024-11-26T13:18:10.813Z","updated_at":"2025-06-13T13:08:09.031Z","avatar_url":"https://github.com/damianc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hot Generator\n\nWraps a generator so that it shares the current value among all the instances.\n\n## Usage\n\n```\nvar hotNums = new HotGenerator(function* () {\n\tyield* [1, 2, 3, 4];\n});\n\nvar genA = hotNums();\nvar genB = hotNums();\n\ngenA.next();\n// {value: 1, done: false}\n\ngenB.next();\n// {value: 2, done: false}\n\ngenA.next();\n// {value: 3, done: false}\n\ngenB.next();\n// {value: 4, done: false}\n\ngenA.next();\n// {value: undefined, done: true}\n```\n\n### `last()` method\n\nThe `last()` method of `HotGenerator` receives the last known value returned from any instance of a generator.\n\n```\nvar hotNums = new HotGenerator(function* () {\n\tyield* [1, 2, 3, 4];\n});\n\nvar genA = hotNums();\nvar genB = hotNums();\n\ngenA.next();\n// {value: 1, done: false}\n\ngenB.next();\n// {value: 2, done: false}\n\nhotNums.last();\n// {value: 2, done: false}\n```\n\n### `lastFrom()` method\n\nSimilar to the `last()` method, but here we can explicitly tell what instance of a generator we are interested in.\n\n```\nvar hotNums = new HotGenerator(function* () {\n\tyield* [1, 2, 3, 4];\n});\n\nvar genA = hotNums();\nvar genB = hotNums();\n\ngenA.next();\n// {value: 1, done: false}\n\ngenB.next();\n// {value: 2, done: false}\n\ngenA.next();\n// {value: 3, done: false}\n\nhotNums.last();\n// {value: 3, done: false}\n\nhotNums.lastFrom(genA);\n// {value: 3, done: false}\n\nhotNums.lastFrom(genB);\n// {value: 2, done: false}\n```\n\n### Caveats\n\nCurrently it is impossible to pass arguments to any of the generators. The problem is that each newest instance of a generator would override behavior of all previous, so far defined generators.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamianc%2Fhot-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamianc%2Fhot-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamianc%2Fhot-generator/lists"}