-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(observable): observable can be augmented with a then method and therefore awaitable #3331
Conversation
I was originally in favor of this but thinking it lately, do we really want to expose this in core? It's one-liner anyway, so anyone want this behavior can opt in by having custom wrapper function. Especially exposing |
…therefore awaitable Add a new import targets 'rxjs/awaitable' as well as `rxjs/extensions/awaitable' that will augment the observable prototype with a then method, and also make Observable<T> extend PromiseLike<T>
c7a644f
to
acc6302
Compare
So probably I object this, rather suggest to someone have 3rd-party module, or each consumer opt in by creating fn themselves. |
Generated by 🚫 dangerJS |
I'm honestly on the fence, but it was an easy change and a quick potential win (and it can sit for a while). I know Rx.NET supports I see it as related to the async iterable problem, if we support async iterables via await, it's get more confusing that all observables cannot be awaited, however big a footgun it might be.
|
@david-driscoll Correct, all Observables must be converted to an |
Yeah, we can't really do this. It's been discussed several times in the past. In fact, I think I was the last one to propose it. The problem is that Observables and Promises are fundamentally different in the fact that Observables are lazy and promises are not. Because promises aren't lazy, the expected behavior of |
After we move most people over to using the pipeable operators, I wouldn't be opposed to renaming |
But code-readability benefits much from promise await functionality. If you could do this in some way for observables. Just see
This code will be something like this
Please, consider doing something like this for API calls. Those switchMaps and subscribes when all code shifts to the right is some kind of nightmare. I know about calling |
@drweb86-work your use case looks like it could be improved by just using flatMap |
Okay, after a bit of thinking about this, I don't think we can do it in this manner. It might be better to rename
The truth is that Observables are just a lower level construct. Observables are basically functions. I think we're going to close this one, because it's just not something we can do given the mental overhead and footguns it would put on our users. |
Description:
Add a new import targets
rxjs/awaitable
as well asrxjs/extensions/awaitable
that will augmentthe observable prototype with a then method, and also make
Observable<T>
extendPromiseLike<T>
.I realize we closed #556 but this keeps getting stuck in my head, imo if someone wants to shoot themselves in the foot let them. Right now, as designed, this would be an optional import that has to be made on the consumer side.
As far as naming 🚲🏘 away.
Related issue (if exists):
#556