WICG / observable

Observable API proposal
https://wicg.github.io/observable/
Other
563 stars 13 forks source link

Adds a multiplexed web socket example. #16

Closed benlesh closed 1 year ago

benlesh commented 1 year ago

I'm proposing that we add this multiplexed web socket example. It's one of the cooler things you can do with the available APIs, assuming that we can land a flatMap and finally method.

That said, the "cooler" stuff would require leveraging the new Observable bit a lot more. Things like reconnection, etc.

Fixes #8, and makes progress on #4.

domfarolino commented 1 year ago

Could you add a TODO under the https://github.com/domfarolino/observable#operators--combinators section to consider the combinators that you use in this PR that don't appear in that list (optionally referencing https://github.com/domfarolino/observable/issues/9)? If the examples here are compelling enough we might want to formally supplement the current list of combinators with things like finally() and so on. But I just want to make sure we think it through so adding a TODO to think about those more once we resolve #9 completely would be nice.

domfarolino commented 1 year ago

Actually finally() looks like the only operator you use that isn't in the current list, so better yet, maybe we can just rewrite this example without it if that isn't too hard. Otherwise finally() might indeed just be important enough to include initially, and we can continue as-is with the TODO I recommended.

domfarolino commented 1 year ago

I've rebased this on top of master so you'll probably have to revert your local commits and pull the branch down from scratch to get everything locally.

domfarolino commented 1 year ago

I've updated the example to use token-based cancelation as that's what is described in https://github.com/domfarolino/observable#the-observable-api so far with the Observer dictionary's signal. I'll admit I don't understand finally() very well, so if it is super duper useful maybe we should just directly include it in our planned list of operators/combinators. Otherwise we could just update this example to use error and complete handlers in the Observer dict I guess? I'll rely on you to make the best call here, since you've got more context and experience with Observables.