-
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
RFC: Strawman Proposal for toPromise replacement #5295
Conversation
what about |
technincally, |
My argument for |
@kwonoj Interesting! I feel like that sounds like it's going to settle the first or last promise of a collection of promises, personally. But it's a good idea to look for language from the spec we can work with. I'll think about that one. |
along with naming something rolls my eye is having |
My preference would be last/first, as I think last is the more natural antonym for first. |
usually I create the similar utility as |
I agree that "last" is the most natural antonym for "first" in a vacuum; in this specific context, I think that "final", which connotes completing more strongly than "last" does while being synonymous with regard to ordering in a sequence, is better. |
How about |
It's definitely not in a vacuum; last is already an operator with the same "final" context. And there is a first operator, too.
|
I kinda like |
I think it's going to be weird to have something like this import {last} from 'rxjs';
const something = last(ob$) And assume the user thinks they'll get a Promise as opposed to every other static method imported from // rxjs.ts
export const toPromise<T>(ob$: Observable<T>, isLast = false): Promise<T> {
if (isLast) return internalLast(ob$);
else return internalFirst(ob$);
} |
Okay maybe this is me being nitpicking. Last is (for me) obviously the last value before the stream completed. But first must not be the first value pushed in the stream. It’s not that I don’t like first, but something feels „off„ |
|
My vote is for
|
Okay, I'm back on board with I'm not sure I like just I think I like Thoughts? |
1d15a1e
to
79f5020
Compare
SGTM. Matching the terminology of existing operators and reading nicely with |
Warning: no complain here! Isn't Kinda makes me think, as is, should come out as: Just asking... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
source$.subscribe({ | ||
next: value => { | ||
resolve(value); | ||
subs.unsubscribe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this will handle the degenerate case of an infinite synchronous source. To handle that, I think this would have to unsubscribe via the next callback's this
instead. Thoughts?
@rapzo ... we don't want it to conflict with the |
when used with a hot observable what if i want the index, too? |
Edit: I've updated the API to use
lastValueFrom
andfirstValueFrom
and added tests.The idea here is to add at least one static method to convert an Observable to a Promise. Given that
toPromise
is flawed (citation from elsewhere in the repo needs to go here). The idea is to use static methods and deprecatetoPromise
.The basic API is this:
and additionally this features this idea: