Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128844 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 290191A00BC for ; Thu, 16 Oct 2025 02:19:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1760581174; bh=ocxu8f3Gkosklv7R3qE/sVg2iVeo7eKCs1GC2ot7jCg=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=GWbfdOpU6WIw8AE3IQsM2CqoDYyIY55OSWto7v6TRN5hbiE9a88ImviJiRFb6nYgt A71byTsLIBI5jo6/1PlgGYWNUVtsOAEDt7BARMSQxAV3GMuXt+17k0GcowrIxpmJWy UCB6M7vrUhJIsgSerNQtM23v0t0y8jdNCnEAhw8pUz2Gfwu2MoEN6B6MzUzsTvhGbH 8Th/MhBbwJbrMeD/MmY7MxcHOl10jdWn/x5Rc+iZxAjnX/JqGQX0C9kYnb/zqrnBt3 qSgasnaDUFrHRj4LXZyG/77geSGWRGj8L7/1o2PY2UL05lPOqIJSIq/nPnKPf5RMd1 f9fXvpAH67zmw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CFD5118006A for ; Thu, 16 Oct 2025 02:19:33 +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=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (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, 16 Oct 2025 02:19:33 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 2862AEC0208; Wed, 15 Oct 2025 22:19:28 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Wed, 15 Oct 2025 22:19:28 -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=1760581168; x= 1760667568; bh=pJy3Ea5FnwYDGo+QUrWD1O17UFkLwwyryg2+b2kmgXE=; b=B gk28tJNb+gfo8Ibvcnl5bV0Ny+XOBc/1OuR2W8a/J4KWkHEFCckBdmfZOjMvYa2f Lbkj+FuUj1MiOCnJAU3D+6Umok8PG5E3+MnWZOfQ38s28dRcNw6egRxJVQuFChfJ BXePWcOb3IY9i1J+svjG+zwbbp1e+zyiQTReDVeQ2SsU2b6zsD6LB/AKZGY3K9M+ 2eRsfTMY6etkhXhje524aLOuEbEjCV0aMjzQJoYYtoX8lrhE+B8PKMLbRGAB2bNK oRh7Eqphbr4ByagQHnRamFw8l1jf/ZJeBR3byWF9Gx2wdAO3yr9zwIpHCdhtSl3c ioWv1H0FNeYg4jHkYdlzA== 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= 1760581168; x=1760667568; bh=pJy3Ea5FnwYDGo+QUrWD1O17UFkLwwyryg2 +b2kmgXE=; b=IYV4KYqzN6okwCz+rBf1RiUedFQOlGEQoulk5+xJuFmTQ5ZnX/J XbfRFJGkDnKUpB/zk5jocNliL6CB1h21m6zDD1mrAgauU6qzt9jpwT0wYZyEkXP4 FA4zQ7oFgRRrwksp0urf/i53WUFqnRkGjZl+YDP7C/v74JnTYV/iaK+4IkRpP82f +qOW3MMdOZ9+kHSrtrS6/blPsZdFsLEOWX1Wjm3lUayL6GwcKfM4GvlbfKs3fUkq olckObOFf3i6zYz8udIEv4Nv/ue3+9vqPKzTtdroWHyeK+JXiOm86clrSGotCPKw uSM2u312vGeHBANOSHHTC8lubJbF57rjghA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduvdehtdejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvvefkjghfufgtsegrtderre ertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgv ugdrtghouggvsheqnecuggftrfgrthhtvghrnhepieeuteehvddvfeejhffgieehleehhe dthfefkeejffelgfevvdekudetjeejtddtnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspg hrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepvggumhhonhgu rdhhthesghhmrghilhdrtghomhdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsth hsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id B72181820054; Wed, 15 Oct 2025 22:19:27 -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, 16 Oct 2025 04:19:00 +0200 To: "Edmond Dantes" Cc: internals@lists.php.net Message-ID: <2b9fd3ec-50ca-41e4-985a-274f886df8b3@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 Content-Type: multipart/alternative; boundary=1bb25fdd8ee242988138cdf73072318a From: rob@bottled.codes ("Rob Landers") --1bb25fdd8ee242988138cdf73072318a Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Oct 15, 2025, at 09:53, Edmond Dantes wrote: > Hello. >=20 > > Why doesn=E2=80=99t scope implement Awaitable? >=20 > Let=E2=80=99s say there=E2=80=99s a programmer named *John* who is wri= ting a library, > and he has a function that calls an external handler. > Programmer *Robert* wrote the `externalHandler`. >=20 > ```php > function processData(string $url, callable $externalHandler): void > { > ... > $externalHandler($result); > } > ``` >=20 > John knows which contracts are inside processData, but he knows > nothing about `$externalHandler`. > From the perspective of `processData`, `$externalHandler` acts as a > **black box**. > If John uses `await()` on that black box, it may lead to an infinite w= ait. >=20 > There are two solutions to this problem: >=20 > 1. Delegate full responsibility for the program=E2=80=99s behavior to > *Robert*, meaning to `$externalHandler` > 2. Establish a limiting contract >=20 > Therefore, if a `Scope` needs to be awaited, it can only be done > together with a cancellation token. >=20 > In real-world scenarios, awaiting a `Scope` during normal execution > makes no sense, because you have a `cancellation policy`. > This means that at any necessary moment you can dispose() the `Scope` > and thus interrupt the execution of tasks inside the black box. >=20 > For the `TaskGroup` pattern, which exists in the third version of the > RFC, awaiting is a relatively safe operation, because in this case we > assume that the code is written by someone who has direct access to > the agreements and bears full responsibility for any errors. >=20 > So, `Scope` is intended for components where responsibility is shared > between different programmers, while `TaskGroup` should be used when > working with a clearly defined set of coroutines. >=20 I don=E2=80=99t get it. What does different programmers working on a pro= gram have to do with whether or not scopes implements Awaitable? Scope h= as an await method, it should be Awaitable. await() takes a cancellation= and thus anything Awaitable can be cancelled at any time. I don=E2=80=99= t see why scope is special in that regard. > If John uses `await()` on that black box, it may lead to an infinite w= ait. This is true of any software or code. Knowing whether or not something w= ill ever complete is called The Halting Problem. It is unsolvable, in th= e general sense. You can await() a read of an infinite file, or a remote= file that will take 5y to read because it is being read at 1 bps. Your = clock can fry on your motherboard, preventing timeouts from ever firing.= Your disk can die mid-read, preventing it from ever sending you any dat= a. There is so much that can go wrong. To say that something that has an= await method isn=E2=80=99t Awaitable because it may never return is tru= e for ALL Awaitable tasks as well. It isn=E2=80=99t special.=20 =E2=80=94 Rob --1bb25fdd8ee242988138cdf73072318a Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Wed, Oct 15, 2025, at 09:53, Edmond Dantes wrote:
Hello.

> Why doesn=E2=80=99t scope implement Awaitable?

Let=E2=80=99s say there=E2=80=99s a programmer name= d *John* who is writing a library,
and he has a function that = calls an external handler.
Programmer *Robert* wrote the `exte= rnalHandler`.

```php
function process= Data(string $url, callable $externalHandler): void
{
   ...
    $externalHandler($result)= ;
}
```

John knows which co= ntracts are inside processData, but he knows
nothing about `$e= xternalHandler`.
From the perspective of `processData`, `$exte= rnalHandler` acts as a
**black box**.
If John uses `= await()` on that black box, it may lead to an infinite wait.
<= br>
There are two solutions to this problem:

1. Delegate full responsibility for the program=E2=80=99s behavi= or to
*Robert*, meaning to `$externalHandler`
2. Est= ablish a limiting contract

Therefore, if a `Sco= pe` needs to be awaited, it can only be done
together with a c= ancellation token.

In real-world scenarios, awa= iting a `Scope` during normal execution
makes no sense, becaus= e you have a `cancellation policy`.
This means that at any nec= essary moment you can dispose() the `Scope`
and thus interrupt= the execution of tasks inside the black box.

F= or the `TaskGroup` pattern, which exists in the third version of the
RFC, awaiting is a relatively safe operation, because in this cas= e we
assume that the code is written by someone who has direct= access to
the agreements and bears full responsibility for an= y errors.

So, `Scope` is intended for component= s where responsibility is shared
between different programmers= , while `TaskGroup` should be used when
working with a clearly= defined set of coroutines.


I don=E2=80=99t get it. What does different programmers working= on a program have to do with whether or not scopes implements Awaitable= ? Scope has an await method, it should be Awaitable. await() takes a can= cellation and thus anything Awaitable can be cancelled at any time. I do= n=E2=80=99t see why scope is special in that regard.

If John uses `await()` on that black box= , it may lead to an infinite wait.

This is true of any software or code. Knowing whether or not something = will ever complete is called The Halting Problem. It is unsolvable, in t= he general sense. You can await() a read of an infinite file, or a remot= e file that will take 5y to read because it is being read at 1 bps. Your= clock can fry on your motherboard, preventing timeouts from ever firing= . Your disk can die mid-read, preventing it from ever sending you any da= ta. There is so much that can go wrong. To say that something that has a= n await method isn=E2=80=99t Awaitable because it may never return is tr= ue for ALL Awaitable tasks as well. It isn=E2=80=99t special. 

=E2=80=94 Rob
--1bb25fdd8ee242988138cdf73072318a--