You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
I'm used to working in languages with async/await and so I was excited to discover Coroutine::of. However, after using it for a bit I find the behavior where yield plays a dual role of await and also return to be confusing and result in less-readable code.
I'm wondering if you considered leveraging return rather than yield to return from the async function, restricting yield to only the await role.
Example
How it works today (as I understand it):
if (...) {
yield syncExpression(); // this is just a return value; only obvious if you see the upcoming return
return;
}
if (...) {
yield asyncExpression(); // this is an await and also a return value; only obvious if you see the upcoming return
return;
}
$temp = yield asyncExpression(); // this is just an await, unless it happens to be the last yield
yield $temp + 2; // this is a return value, even though there is no following return (because the function ends)
How I maybe expected it to work:
if (...) {
return syncExpression(); // this is just a return value
}
if (...) {
return yield asyncExpression(); // await a value, then return the result
}
$temp = yield asyncExpression(); // this is just an await
return $temp + 2; // this is just a return value
// if we get to the end of the function without returning, we have a void promise
Additional context
I'm a PHP novice; so if there are good reasons why this was done, I'd love to understand the details!
The text was updated successfully, but these errors were encountered:
Description
I'm used to working in languages with async/await and so I was excited to discover
Coroutine::of
. However, after using it for a bit I find the behavior whereyield
plays a dual role ofawait
and alsoreturn
to be confusing and result in less-readable code.I'm wondering if you considered leveraging
return
rather thanyield
to return from the async function, restricting yield to only theawait
role.Example
How it works today (as I understand it):
How I maybe expected it to work:
Additional context
I'm a PHP novice; so if there are good reasons why this was done, I'd love to understand the details!
The text was updated successfully, but these errors were encountered: