{"id":17987779,"url":"https://github.com/dirkluijk/promise-stream","last_synced_at":"2026-01-20T01:58:29.981Z","repository":{"id":254251606,"uuid":"845951846","full_name":"dirkluijk/promise-stream","owner":"dirkluijk","description":"A stream-like Promise for JavaScript","archived":false,"fork":false,"pushed_at":"2024-09-22T08:37:30.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-22T08:38:43.292Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dirkluijk.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-22T08:49:15.000Z","updated_at":"2024-09-22T08:37:33.000Z","dependencies_parsed_at":"2024-08-22T10:09:03.106Z","dependency_job_id":"b0886bcb-fe5d-4341-ad33-0288defcdf73","html_url":"https://github.com/dirkluijk/promise-stream","commit_stats":null,"previous_names":["dirkluijk/promise-stream"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Fpromise-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Fpromise-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Fpromise-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Fpromise-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dirkluijk","download_url":"https://codeload.github.com/dirkluijk/promise-stream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222099607,"owners_count":16931447,"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-10-29T19:09:37.521Z","updated_at":"2026-01-20T01:58:29.950Z","avatar_url":"https://github.com/dirkluijk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PromiseStream 🌊\n\n\u003e A stream-like promise that emits multiple values over time\n\n[![NPM version](http://img.shields.io/npm/v/@dirkluijk/promise-stream.svg?style=flat-square)](https://www.npmjs.com/package/@dirkluijk/promise-stream)\n[![NPM downloads](http://img.shields.io/npm/dm/@dirkluijk/promise-stream.svg?style=flat-square)](https://www.npmjs.com/package/@dirkluijk/promise-stream)\n[![Build status](https://github.com/dirkluijk/promise-stream/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/dirkluijk/promise-stream/actions/workflows/main.yml)\n\n## Overview\n\n### What? 🤔\n\nA simple building block that behaves like a regular `Promise\u003cT\u003e`, but can emit multiple values over time. \n\n* Compatible with async/await (awaits completion)\n* Provides built-in async iterator\n* Contains configurable buffer size\n\n### Limitations \u0026 when to use? 🤷‍♂️\n\nLike regular promises, a `PromiseStream\u003cT\u003e` is not cancellable, is hot, shared, and will replay the last value.\nFurthermore, no built-in operator support (like map or flatMap) is currently provided.\n\nThe limitations are intended. For extensive reactive apps I would recommend to use RxJS instead.\n\n### Roadmap ideas 💡\n\n* Provide built-in RxJS compatibility utils\n* Support different backpressure mechanisms\n\n## How to use 🌩\n\n### Install\n\n```\nnpm install @dirkluijk/promise-stream\n```\n\n### Creating a `PromiseStream\u003cT\u003e`\n\nThis works the same as a regular `Promise`, but you have three callbacks: `next`, `complete` and `error`.\n\n```typescript\nimport { PromiseStream } from '@dirkluijk/promise-stream';\n\nconst myStream = new PromiseStream\u003cstring\u003e((next, complete, error) =\u003e {\n    next('foo');\n    next('bar');\n    next('baz');\n    complete();\n})\n```\n* `next` always expects a value\n* `complete` never expects a value\n* `error` accepts an optional error value\n* once completed or failed, no values are accepted anymore\n\n### Consuming a `PromiseStream\u003cT\u003e`\n\nYou can use callbacks:\n```typescript\nmyStream\n    .iterate(value =\u003e {\n        // executed when value is emitted\n    })\n    .then(() =\u003e {\n        // executed when completed\n    })\n    .catch((error) =\u003e {\n        // executed when failed\n    })\n```\n\nSince a `PromiseStream` invokes the `.then()` callback upon completion, it is compatible with async/await:\n\n```typescript\ntry {\n    await myStream.iterate(value =\u003e {\n        // executed when value is emitted\n    });\n} catch (error) {\n    // executed when failed\n}\n\n// executed when completed\n```\n\nAdditionally, you can also use the async iterator:\n```typescript\ntry {\n    for await (const value of myStream.asyncIterator()) {\n        // executed when value is emitted\n    };\n} catch (error) {\n    // executed when failed\n}\n\n// executed when completed\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkluijk%2Fpromise-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirkluijk%2Fpromise-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkluijk%2Fpromise-stream/lists"}