Re: PHP True Async RFC Stage 4

From: Date: Thu, 23 Oct 2025 07:43:17 +0000
Subject: Re: PHP True Async RFC Stage 4
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  Groups: php.internals 
Request: Send a blank email to internals+get-128922@lists.php.net to get a copy of this message
On Thu, Oct 23, 2025, at 08:41, Edmond Dantes wrote: > Hi > > > Assuming an awaitable is idempotent (such as the result of a coroutine), this is an > > infinite loop. There’s a 99.9% chance that’s unintended, which is part of the point of static > > analysis. > > ```php > foreach(($next = await($awaitable)) as $value) { } > ``` > > executed as: > 1. await($awaitable) - will return some value > 2. foreach got this value > 3. If the value has a valid interface, then foreach will iterate over it. > > await($awaitable) - > > It always returns only one value because under the hood it works like this: > > ``` > function await(awaitable): > # 1) Create a waker for the current coroutine > waker = Waker(current_coroutine) > > # 2) Register an event handler inside the awaitable > handler = function(result, error): > waker.set_result(result, error) > awaitable.remove_handler(handler) # detach > Scheduler.enqueue(waker.coroutine) > > awaitable.add_handler(handler) > > try: > # 3) Suspend the current coroutine until resumed > Scheduler.suspend(current_coroutine) > > # 4) When the waker is triggered, return the stored result > return waker.get_result() > > finally: > # 5) Destroy/cleanup the waker object > waker.dispose() # release buffers/slots > ``` > > > The RFC says that for coroutines, but not Awaitable. It is undefined. > Sorry I can’t understand the meaning of this. > > Thanks, Ed Nowhere in the RFC does it explain how await() applies to the Awaitable interface, it only specifies it in the context of a coroutine. — Rob

« previous php.internals (#128922) next »