Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128922 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id C0B471A00BC for ; Thu, 23 Oct 2025 07:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761205425; bh=IwaXL01srt6xdmyXpYnpJNapuGsszH28bCfuTI0fqDA=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=mIi1FUXgzrWI5/97m9uzCm4Y4W9KLM3DqxwEtyIIthMuZ4O+lOEc3NG5wXsUp0RTr YEL+oBPQHYKoI3r4dTLp+hJPUC4HXk+Ecz+hsurcZEbvu8c6FAXBJ7fEDPLjY0u4u2 4sufSLZ+ChnQk3xrHr5hJTK114PhFbQXPHdN3AGw+thKW723FfdQdZpbE03gQTUI4J rl+MAXc3GljTc6yG8EU+t25IgFCs48OkQgsHkQTh7vqdrBQJjK7YpS8M1+DW2DqNrz R8iSegW9h1QSHC9iCzUn50byZIooKRrxBYgd3nolrWqG4+xVOtSgr70mMFW3a1WcZx MG7Xk4eC8a+vQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F24B21801E8 for ; Thu, 23 Oct 2025 07:43:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 23 Oct 2025 07:43:43 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 41997EC00C7; Thu, 23 Oct 2025 03:43:38 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Thu, 23 Oct 2025 03:43:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1761205418; x= 1761291818; bh=LcvaQXVw4LYIslEyVkMmoCMwsd9Uh41h4GDov8vDFZQ=; b=U FQwD+gF2/dxFzPyS95UEx7tJDWGJxPITQ9E1tnXQDcPf+osPJllZteUuFw6up+VC y2OZsAg3aJMOVogXjHWsCVigkUG0IPYHMqGeVVvugDrFuxxNkYaHdYA6zLPADeCL BADA4z7044e0m8uZM/6U1FKoHJY7SsI8WUZt3sitlZdmH4u5TzFw6utBRAvrWhrW CLaqGk9rDIi/ecGX9t3fJW98mdVjy0dct1A3UWq2nN8PaLYco5DFp8UtwhIAcoZi 64vqB85Q6uA8e4wF0Kg1bOkfLkloDhW7g1UnW6qRkfuDqE6TciCL81CZUYAWoiMk OIGCME5QD1rje0kYhcC8w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1761205418; x=1761291818; bh=LcvaQXVw4LYIslEyVkMmoCMwsd9Uh41h4GD ov8vDFZQ=; b=IxGt1mGOpjId9I9EOrDZhrVonHsFOBS0QNMoBqak1QjP3fX2b9u 7mHfSVWEofMbtXqIvIPp8qllVYB25VuT03omgy9ATTdb56jHeDTtVil0K3ufEhxr qaijAU6MMs5eItyi2rWDYPOXFJ1sE76uHXuivuzn9b/KOoreQIpxT9lhHm0Bwg1K FonL63GgJwe2fUO2LI2jx+PkhXdwb2ORFh8EOS05ZyCWyYYmx2eirZR6jpWsGbrv C09QtB0/GHfRnpBE7d3q+0uEx4moiUrXGWqFk45vnmdhDvhVRas+oPP3eE5H/wPq MfAGI4Gf5uCLzBr1io/kisLkAYLekusv3+Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddugeehkeelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfn rghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtth gvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfhfeekjefflefgvedvkeduteejjedt tdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehroh gssegsohhtthhlvggurdgtohguvghspdhnsggprhgtphhtthhopeefpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopegvughmohhnugdrhhhtsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvthdprhgtphhtthho pegrrghrohhnsehtrhhofihskhhirdgtohhm X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id C7B8E182008A; Thu, 23 Oct 2025 03:43:37 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AG5VjklPAjNR Date: Thu, 23 Oct 2025 09:43:17 +0200 To: "Edmond Dantes" Cc: "Aaron Piotrowski" , "PHP Internals" Message-ID: In-Reply-To: References: <0e4e39d6-9cc9-4970-92e0-2463143b4011@app.fastmail.com> <37180d8d-85b4-49a3-a672-334bf4329470@app.fastmail.com> <2f8524a7-dea2-4fbf-933a-c538d3706253@app.fastmail.com> <151800a7-1094-49bc-8e43-c593a74741af@app.fastmail.com> <772a457f-69b6-4a76-8224-081917d719f6@app.fastmail.com> <8c20e8cc-cec7-4aa5-b6a7-663ef8159e1a@app.fastmail.com> Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 Content-Type: multipart/alternative; boundary=2c9d7dc5b1ef472ca8c9d93560ed0eff From: rob@bottled.codes ("Rob Landers") --2c9d7dc5b1ef472ca8c9d93560ed0eff Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Oct 23, 2025, at 08:41, Edmond Dantes wrote: > Hi >=20 > > Assuming an awaitable is idempotent (such as the result of a corouti= ne), this is an infinite loop. There=E2=80=99s a 99.9% chance that=E2=80= =99s unintended, which is part of the point of static analysis. >=20 > ```php > foreach(($next =3D await($awaitable)) as $value) { } > ``` >=20 > 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. >=20 > await($awaitable) - >=20 > It always returns only one value because under the hood it works like = this: >=20 > ``` > function await(awaitable): > # 1) Create a waker for the current coroutine > waker =3D Waker(current_coroutine) >=20 > # 2) Register an event handler inside the awaitable > handler =3D function(result, error): > waker.set_result(result, error) > awaitable.remove_handler(handler) # detach > Scheduler.enqueue(waker.coroutine) >=20 > awaitable.add_handler(handler) >=20 > try: > # 3) Suspend the current coroutine until resumed > Scheduler.suspend(current_coroutine) >=20 > # 4) When the waker is triggered, return the stored result > return waker.get_result() >=20 > finally: > # 5) Destroy/cleanup the waker object > waker.dispose() # release buffers/slots > ``` >=20 > > The RFC says that for coroutines, but not Awaitable. It is undefined. > Sorry I can=E2=80=99t understand the meaning of this. >=20 > 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. =E2=80=94 Rob --2c9d7dc5b1ef472ca8c9d93560ed0eff Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


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=E2=80=99s a 99.9% chan= ce that=E2=80=99s unintended, which is part of the point of static analy= sis.

```php
foreach(($next =3D await(= $awaitable)) as $value) { }
```

execu= ted as:
1. await($awaitable) - will return some value
2. foreach got this value
3. If the value has a valid interf= ace, then foreach will iterate over it.

await($= awaitable) -

It always returns only one value b= ecause under the hood it works like this:

```
function await(awaitable):
    # 1) Cr= eate a waker for the current coroutine
    wake= r =3D Waker(current_coroutine)

  &nbs= p; # 2) Register an event handler inside the awaitable
 &= nbsp;  handler =3D function(result, error):
  &= nbsp;     waker.se= t_result(result, error)
     &nbs= p;  awaitable.remove_h= andler(handler) # detach
      &= nbsp; Scheduler.enqueue(waker.coroutine)

    awaitabl= e.add_handler(handler)

    t= ry:
        # 3) Suspend th= e current coroutine until resumed
    &nbs= p;   Scheduler.suspe= nd(current_coroutine)

   &nb= sp;    # 4) When the waker is triggered, return the store= d result
        return&nbs= p;waker.get_result()

    finally:
    &nb= sp;   # 5) Destroy/cleanup the waker object
 &n= bsp;      waker.dispose()        &nbs= p;         # release buffers/slo= ts
```

> The RFC says that for cor= outines, but not Awaitable. It is undefined.
Sorry I can=E2=80= =99t understand the meaning of this.

Thanks, Ed=

Nowhere in the RFC does it ex= plain how await() applies to the Awaitable interface, it only specifies = it in the context of a coroutine.

=E2=80=94 Rob
--2c9d7dc5b1ef472ca8c9d93560ed0eff--