race(
timer(2000).pipe(mapTo(1)),
timer(1000).pipe(mapTo(2)),
).toPromise().then(r => console.log(r))
Code above will output 2.
If I have an action that I try to repeat until condition is met but ignore it if it takes too long, then I take an approach in this answer https://stackoverflow.com/a/51644077
The problem is that race never finishes with the shortest function. The longActionObservable repeats until the condition is met and empty() is called.
const o = longActionObservable();
race(
o.pipe(expand(v => v < 100 ? empty() : o)), // no toArray because I do not need result
timer(2000),
).toPromise()
This code does not return a promise that will ever resolve. I'm wondering why is this approach so fragile to this kind of behavior? If there's one observable timer(2000) that most surely ends, why doesn't race end?