Re: PHP True Async RFC Stage 4

From: Date: Thu, 23 Oct 2025 06:41:46 +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  Groups: php.internals 
Request: Send a blank email to internals+get-128917@lists.php.net to get a copy of this message
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

« previous php.internals (#128917) next »