-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
Changing "when" to "onResolve" or "onComplete" #77
Comments
Specifically |
|
@J7mbo Somebody mentioned |
|
@kelunik Well take a look at jQuery (great example, I know!), I think we had |
@PeeHaa A promise is a placeholder for the outcome of an operation. And that operation is complete then. It won't change anymore. @J7mbo They still have |
Also ping @rdlowrey |
In some contexts function ($stream) {
yield $stream; // this doesn't read well at all. What are we even waiting for here?
} I would prefer this: function ($stream) {
yield $stream->awaitEnd(); // or whenEnded()
} Regarding the name a()->when($b); // in English this reads as "do $a when $b", which is the opposite of what the code does |
@joshdifabio One such example of (optional) emits as a stream is Artax. The main purpose of |
My point was that naming the method |
Oh, I didn't mean As we have |
@bwoebi You wanted 2-3 days to think about it. How do you feel now? |
I still really don't like it. |
Not saying I disagree with the gist @bwoebi, but saying something sounds like something else to make something more clear is weird imo. |
It's just a single advantage, not the whole argument ;-) |
It makes the API consistent. We have
You can bring that argument for every single name. It's not an argument.
Indeed, and that's an argument against using
Could you explain why it's backwards? |
The Deferred is just one implementation, which returns a Promise when some method is called. It's a separate API from Promise. It makes sense to model the naming of the Deferred methods after the method(s) of the Promise, but not vice-versa.
Most APIs do not have so much complexity behind. - No.
I just disagree. If it were the same, we'd call it then(). Throw/return/chain are just one thing: it transforms the promise. There's the only difference. We do not return a transformed promise. For everything else, it's quite the same thing.
Our current naming is totally fine and you're proposing something worse… |
It's the standard implementation.
It's not the only difference. The second difference is one callback instead of two. And transforming the promise or not is exactly the difference between
Our promises aren't really complex, they're quite simple, as they don't have any chaining or something like that. They just fire a simple callback (or a set of them) on resolution. |
Well, I never liked the name done() … But I'd even prefer done() over onResolve() … it's just too clumsy for me...
Tell that someone who's never interacted with Promises in his life ;-) |
In that case our streams shouldn't extend
Using
Not being able to understand things is mostly not due to promises, but rather due to generators or not understanding the event loop is the scheduler. |
It doesn't matter for normal promises, but I think it matters for more advanced use cases where the promise API is just one way of consumption. Looking at a list of functions,
onResolve
/onComplete
are way more expressive thanwhen
.The text was updated successfully, but these errors were encountered: