Open benlesh opened 3 weeks ago
Unrelated: I've long wanted a
timeout(ms, { signal })
API that returns a Promise
Me too. Last I checked this is proposed as part of the scheduler API as scheduler.wait
, which seems like very much the wrong place for it to me, but browsers are unlikely to want to duplicate such any API anywhere else if it does land there.
I see that proposal mentions possible future integration with Observable, actually.
How much of this is captured by https://github.com/WICG/observable/issues/72?
I left my comments on https://github.com/WICG/observable/issues/72#issuecomment-2359379069
Just for discussion about another possible use case for observable
One thing that observables get used for frequently is for timing and animations. The APIs available are fine, but they're mildly cumbersome to use.
If, for example, we had an observable that did what
setInterval
does, it would make intervals a lot more portable and usable in reactive chains, as well as easier to clear in a unified way, because of the use ofAbortSignal
:Which means this would work:
And it could be used to delay things in chains like so:
What it would provide is honestly debatable. RxJS provides an incrementing number, but IMO, that's sort of arbitrary. We might provide something like what
requestAnimationFrame
does, which is a high resolution timestamp.requestAnimationFrame
is another API that is used a lot, although in a recursive way, in observables. Usually people make animation loops like so:But with an observable API it could look like something like what I've written below. The RxJS version of this also provides elapsed time along with the timestamp, but that's probably not necessary, it's just really useful when animating things.
Unrelated: I've long wanted a
timeout(ms, { signal })
API that returns a Promise, butinterval(ms).first({ signal })
will suffice.