On Thu, Oct 23, 2025, at 09:59, Edmond Dantes wrote: > I’d like you to have the full information necessary to make an > informed decision. > > There are two or more channel objects that need to be awaited. How > should this be implemented? > > Currently > ```php > [$result1, $result2] = awaitAny($channel1, $channel2); > ``` > > With Futures: > ```php > // Like Rust > [$result1, $result2] = awaitAny($channel1->recv(), $channel2->recv()); > ``` > > What I dislike about the Future example is that it creates an object > that isn’t actually needed. > What I like about it is that it clearly shows what action is being awaited.
Specifically: > What I dislike about the Future example is that it creates an object > that isn’t actually needed. Why does it need to 'create' an object? Flyweights are a well known pattern and PHP knows the number of references to any specific object. Prevent them from being GC'd and have a pool of them for reuse. You don't need to actually create anything. That being said, that's an optimization for later. As for which one I'd rather have, I'd rather have the one where my examples hold true: assert(awaitAll($a, $b, $c) === [await($a), await($b), await($c)]); It's clear what it does and that it is just a shorthand. When that fails, we have issues. — Rob
