https://github.com/jamen/pull-regenerate
A source that masks other sources over its lifetime.
https://github.com/jamen/pull-regenerate
Last synced: 10 months ago
JSON representation
A source that masks other sources over its lifetime.
- Host: GitHub
- URL: https://github.com/jamen/pull-regenerate
- Owner: jamen
- License: mit
- Created: 2018-04-21T18:05:56.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-21T18:06:08.000Z (about 8 years ago)
- Last Synced: 2025-04-02T11:24:18.982Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# pull-regenerate
> A source that masks other sources over its lifetime.
## Install
```sh
npm i pull-regenerate
```
## Usage
### `regenerate(initial, swap)`
Create a [`pull-stream` source][1] that masks other sources over its lifetime. Instead of aborting when the initial stream aborts, it uses a new source returned from `swap(nth, abort)`, where `nth` is the amount of times it has swapped and `abort` is a function that lets you actually abort.
The stream also has `abort()` and `set(stream)` methods attached.
```js
let source = regenerate(
values([ 1, 2, 3 ]),
(nth, abort) => {
if (nth > 10) return abort()
return values([ i + 1, i + 2, i + 3 ])
}
)
if (something) {
source.set(
values([0, 1, 2, 3])
)
} else if (otherthing) {
source.abort()
}
pull(
source,
collect((err, data) => {
console.log(data)
})
)
```
[1]: https://github.com/pull-stream/pull-stream/blob/master/docs/spec.md#source-streams