{"id":15669133,"url":"https://github.com/knorpelsenf/strom","last_synced_at":"2025-05-06T20:05:05.900Z","repository":{"id":172881022,"uuid":"649887247","full_name":"KnorpelSenf/strom","owner":"KnorpelSenf","description":"The ultimate streaming library for Deno","archived":false,"fork":false,"pushed_at":"2025-01-09T15:22:56.000Z","size":235,"stargazers_count":6,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T02:22:09.668Z","etag":null,"topics":["async","deno","iterator","stream"],"latest_commit_sha":null,"homepage":"https://deno.land/x/strom","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/KnorpelSenf.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":"2023-06-05T21:26:51.000Z","updated_at":"2024-05-30T12:32:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"a8c80671-3aa6-43f6-aad8-d4c954041548","html_url":"https://github.com/KnorpelSenf/strom","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":"0.018867924528301883","last_synced_commit":"f3cbb18935d5b8a715aeba068db074fabe9caf61"},"previous_names":["knorpelsenf/strom"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnorpelSenf%2Fstrom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnorpelSenf%2Fstrom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnorpelSenf%2Fstrom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnorpelSenf%2Fstrom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KnorpelSenf","download_url":"https://codeload.github.com/KnorpelSenf/strom/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252761130,"owners_count":21800124,"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","deno","iterator","stream"],"created_at":"2024-10-03T14:21:37.801Z","updated_at":"2025-05-06T20:05:05.840Z","avatar_url":"https://github.com/KnorpelSenf.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# strom\n\nThe ultimate streaming library for Deno.\n\n- completely async\n- fully concurrent\n- trivial to use\n- built around iterators\n\nstrom lets you morph iterators in concise functional ways:\n\n```ts\nstrom([3, 1, 4])\n  .map((x) =\u003e [x, x * x])\n  .filter(([, sq]) =\u003e sq \u003c 10)\n  .run((pair) =\u003e console.log(pair));\n// [ 3, 9 ]\n// [ 1, 1 ]\n```\n\nstrom is async. This means that all elements are passed lazily only once they\nare needed—just like with async iterators!\n\nIn JavaScript, if you build longer chains of async iterators, this comes with a\nperformance penalty. Several async iterators will be run in sequence, lacking\nconcurrency. We will now see how strom is much faster than plain old iterators.\n\nLet's say you have a data source that produces values slowly, such as data from\nIO operations.\n\n```ts\nasync function sleep() {\n  await new Promise((r) =\u003e setTimeout(r, 1000));\n}\nasync function* values() {\n  for (const n of [3, 1, 4]) {\n    console.log(\"producing\", n);\n    await sleep();\n    yield n;\n  }\n}\n```\n\nLet's now say you want to perform more slow async ops for these values.\n\n```ts\nasync function inc(n: number) {\n  await sleep();\n  return n + 1;\n}\nasync function double(n: number) {\n  await sleep();\n  return n + n;\n}\n```\n\nWith iterators, it could look something like this.\n\n```ts\nasync function* incItr() {\n  for await (const n of values()) yield await inc(n);\n}\nasync function* doubleItr() {\n  for await (const n of incItr()) yield await double(n);\n}\n\nconsole.time(\"iterators\");\nfor await (const elem of doubleItr()) {\n  console.log(\"computed\", elem);\n}\nconsole.timeEnd(\"iterators\");\n```\n\nThe output is:\n\n```bash\nproducing 3\ncomputed 8\nproducing 1\ncomputed 4\nproducing 4\ncomputed 10\niterators: 9020ms\n```\n\nAs you can see, the elements are passed through the iterators one after the\nother. There is no concurrency. This is by design of the\n[async iterator protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols).\n\nLet's look at the same code written with strom:\n\n```ts\nconst iter = strom(values()).map(inc).map(double);\n\nconsole.time(\"strom\");\nfor await (const elem of iter) {\n  console.log(\"computed\", elem);\n}\nconsole.timeEnd(\"strom\");\n```\n\nCheck the output:\n\n```bash\nproducing 3\ncomputed 8\nproducing 1\ncomputed 4\nproducing 4\ncomputed 10\nstrom: 9016ms\n```\n\nSo strom does the same thing as iterators by default (just in a more concise\nway).\n\nLet's speed things up by allowing strom to buffer elements. That way, it can\nalready fetch the next element while processing the current one, which gives us\nfull concurrency!\n\n```ts\nconst iter = strom(values()).map(inc).map(double).parallel(5);\n\nconsole.time(\"strom\");\nfor await (const elem of iter) {\n  console.log(\"computed\", elem);\n}\nconsole.timeEnd(\"strom\");\n```\n\nSuddenly, it's MUCH faster:\n\n```bash\nproducing 3\nproducing 1\nproducing 4\ncomputed 8\ncomputed 4\ncomputed 10\nstrom: 5012ms\n```\n\nWhenever you are working with async iterators, you are missing out on\nconcurrency and readability.\n\nUse strom.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknorpelsenf%2Fstrom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknorpelsenf%2Fstrom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknorpelsenf%2Fstrom/lists"}