Hi

> Awaitables should always represent a single value. Awaiting multiple times 
> should never result in a different value.
Where did this rule come from?

In programming languages (except Rust), there is no explicit
restriction on the behavior of the await operation, nor a specific
requirement that it must always return the same value. However, from a
usability perspective, such a rule would make the code simpler. But...

On the other hand, if we restrict the behavior of await, we fail to
cover the full range of possible cases — and that’s also bad.

> AMPHP has a pipeline library, https://github.com/amphp/pipeline,

That’s not quite the same.
The general case of interacting with Awaitable objects looks like this:

```php

// Waiting for the first event from any object in the set.
// The objects in the set are of different types.
awaitAny(obj1, obj2, obj3); // or All ...

```

But, programming languages don’t always implement this **general
case**, and sometimes even try to avoid it altogether.
And working with a data stream is implemented differently through
`await foreach`.

There is another way to solve this problem (all Futures only) —
through a method that always returns a new Future. For example:
```php
// $queue->whenReady() returns Future object
awaitAll($future, $queue->whenReady());
```
Downside: each time we create a new object in memory, while the loop
still remains.

At the moment, I don’t see any compelling reason to impose artificial
restrictions on behavior.
* Future objects are a special case of Awaitable objects,
* while Awaitable objects represent the general case.

> I think you should consider additional time beyond only two more weeks for 
> discussion of this RFC before bringing it to a vote.
> PHP 8.6 or 9 is some time away. This is definitely not an RFC to rush to 
> voting.

I have no objections.

Thank you, Ed

Reply via email to