Andarist / Andarist/callbag-pull-when

Pull sampler when input source emits

Ouverte
#1 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
7
Forks
1
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

First of all, I wanted to say I like how this operator allows to interfrate pullable and listenable sources to form powerful complex pipelines.
In this sense, I propose a feature request which would make it even more powerful.

With the current implementation, we can provide a listenable sampler that tells us when to pull, e.g. an `interval` that emits every second.

However, there is no easy way to pull the source based on its emissions, like pulling it whenever it another item whenever we get one etc.

But this can easily be achieved by pulling the sampler whenever the input emits, possible passing along the data as well.

This simple (andfully backwards-compatible) change would open some cool possibilities.
For example, you could can pull another item after each emission, but first waiting a certain amount of time:

```javascript
pipe(
range(1, 100),
pullWhen(pipe(
fromIter(function* () { // some infinite pullable
while (true) yield 0;
}),
switchMap(_ => timer(1000)),
startWith(0) // start immediately
)),
observe(x => console.log(x)) // logs 1, 2 ... with pauses of 1 sec in between
)
```

Another possibility would be to wait for `n` emissions before pulling `n` more items.

If you want, I can create a pull request for this.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.