Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128853 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 092721A00BC for ; Thu, 16 Oct 2025 11:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1760614323; bh=QuwqrJhC08qM7zjAul41/0cKtSaT+hY90lD/HzVHN+o=; h=Date:From:To:In-Reply-To:References:Subject:From; b=K5ugJEVb3+cz8xsYyl0HaNtu+eyePZU9CThij9UhF5XRElo7c92VMll3IlWRxlmYt r6sAZEXqDxpOXNIr1suAmlylurFzXyw7CN13HniSrDAOWDp5ZLSbjYyfFfB3tz+cOk M9G1EhUDHYsFXorgCVeblmau9VI4WrjL+b8Gqrtv/Qd+HPH5Ky3FPfGt536sqkVllx OAf6ADG8W9HJnkSFFzCCZu3JEmZfWDLuhNb14f/OVjz6oCOU6CqGNr2y6gGC8YqGnU QGBbf0VXHKKo2PnHoc52WTNNS0fN6MntGzAJj6vAkUta0G/El8DeKxSl/P+A2Ffekm GhjksxrYdFGXw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9289B180084 for ; Thu, 16 Oct 2025 11:32:02 +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.9 required=5.0 tests=BAYES_40,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 fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (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 11:32:02 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 888EA7A00AB for ; Thu, 16 Oct 2025 07:31:56 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Thu, 16 Oct 2025 07:31:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=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=1760614316; x=1760700716; bh=QuwqrJhC08 qM7zjAul41/0cKtSaT+hY90lD/HzVHN+o=; b=NHC1JWlwRhxxeg56BoEFP5/A0B HZsbesDj+GmV4MkHOushmdg1RRpSMFLkHLcWDZ//P9WOFwe32ickuZlK+vh5W27o XRPidY8aBWQSYuDI94AalI+FbxFKVifoKxmqrLb6DdjULFT3cEqTXT3MGRkjfiJg 6vVwKqtmBh/hLZ5ys9uLQcEKAiZ+9hsRXxZBqyVKloA6m3PJzUz9WCRQ6jsKxcLM 6mkMy5rvvMn2USSYP7ZyIg18OPBCs0dsdbFXinnTtYUwxpZpMGSKi7hmRoU2yejy bTQ/iA35l4KbxiGD+CALxDUZMnnhKfBy+Lp9TBKv3OrY+EQCyQxE3mqkRwZg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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= 1760614316; x=1760700716; bh=QuwqrJhC08qM7zjAul41/0cKtSaT+hY90lD /HzVHN+o=; b=hXwJFO8ZOB/n6HQconQQadkiIHHKHkDy6rr8j3/Z2mUv7hY4yxl weohwXw+ArTrhL66Mf3jy21XZJAxib8OMWG/Roxt8VjeJUkkSqmyve0DMNL6zEa3 Re+Ig/cMxnxojnBHO89t0V0hu1oo0bd2DLfojf+4SDguBOCnS81bxATOl8P50t2D /VgKKJ+7qBEHmGkpSUx4wv4g9zydJt+Si1TOeTKMCzV3HFHlP6ap4e1VouIIumf4 FhBFs4yopJ1F5tNwmykNasVu0enCQJgdl2DnwfaAc/MYBA/JmesAg1BmsJolo7vp pVB5cz1LRJEOfPLDskig3qJBhD1g3TDze6g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduvdeiudekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvkfgjfhfutgesrgdtreerre dtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggu rdgtohguvghsqeenucggtffrrghtthgvrhhnpedtueejtdethfeulefhtdelieduteelff dtudelheffgedtieehhfelieejgfevgeenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprh gtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgr lhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 0AC531820054; Thu, 16 Oct 2025 07:31:56 -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 13:31:21 +0200 To: internals@lists.php.net Message-ID: <436d4ede-c08e-4e7d-9ae2-8342f7f827ed@app.fastmail.com> In-Reply-To: References: <2b9fd3ec-50ca-41e4-985a-274f886df8b3@app.fastmail.com> <2e39e211-c816-41db-a079-f2c6b3934e0a@app.fastmail.com> Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 Content-Type: multipart/alternative; boundary=8d407de2dabc43d4b3d5f6e0712d34a1 From: rob@bottled.codes ("Rob Landers") --8d407de2dabc43d4b3d5f6e0712d34a1 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Oct 16, 2025, at 09:38, Daniil Gentili wrote: >=20 > > You've provided examples and said that it violates design and fundam= ental elements, but not which design and fundamentals, ie, the evidence = for the decision. I would expect more than "because I said so" for such = a huge language feature, but rather arguments grounded in computer scien= ce.=20 >=20 >=20 > He very explicitly described the issue, in objective terms: a breach o= f agreement in the context of the invocation of a foreign interface. >=20 > In simpler terms, you can't and should not be able to mess with the in= ternals of code you didn't write: this is similar to the principle of en= capsulation in OOP, where you cannot modify private properties of an obj= ect. >=20 >=20 > Cancellation should be part of the contract of an async function: it i= s safe, and most async languages already implement it explicitly by pass= ing a context or a cancellation token, the current approach of the RFC d= oes it implicitly, which is also fine. >=20 > Awaiting for the completion of spawned coroutines should *not* be part= of the contract of an async function: it is an incredibly easy footgun,= as it's incredibly easy to spawn a coroutine meant to i.e. run until th= e object is destroyed, and then encounter a deadlock when the linked sco= pe is awaited for before the object is destroyed (even messier if cycles= and thus the GC are involved). >=20 > Languages like Kotlin that do implement await on scopes have already r= ealized that it is a mistake, as can be seen by the many warnings agains= t using await on a scope, as I already linked in previous emails. >=20 > On the other hand, making the same mistake described above, by cancell= ing a scope, will produce a very easy to debug exception instead of a de= adlock, easily fixable by (warning the author of the library class) to u= se a new scope to spawn coroutines within the object. >=20 > Awaiting a scope leads to deadlocks in case where a separate scope is = needed but not used, cancelling them leads to a simple exception. > Awaiting on multiple tasks can already be done, explicitly, with TaskG= roup. >=20 >=20 > Regards, > Daniil Gentili. Hey Daniil and Edmond, I think I understand the intention. Would it be better to instead of hav= ing ->awaitCompletion (which feels like an implicit implementation of Aw= aitable without an explicit implmentation -- which is the part that was = bothering me), maybe having something like ->joinAll() or ->joinOnCancel= lation()? That way someone like me won't come along and wrap them in an = Awaitable because it looks Awaitable. It also might be a good idea to make specifying a timeout in ms mandator= y, instead of a taking an Awaitable/Cancellation. This would also preven= t people from simply passing a "never returning" Awaitable thinking they= 're being clever. It also might be good to provide a realistic looking example showing a "= bad case" of how this is dangerous instead of simply saying that it is, = showing how a scope is not a 'future', but a container, and preemptively= mention TaskGroups, linking to the future scope (which it should also p= robably be listed there as well). =E2=80=94 Rob --8d407de2dabc43d4b3d5f6e0712d34a1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Thu, Oct 16, 2025, at 09:38, Daniil Gentili wrote:<= /div>

> You've provided example= s and said that it violates design and fundamental elements, but not whi= ch design and fundamentals, ie, the evidence for the decision. I would e= xpect more than "because I said so" for such a huge language feature, bu= t rather arguments grounded in computer science. 


He very ex= plicitly described the issue, in objective terms: a breach of agreement = in the context of the invocation of a foreign interface.

In simpler terms, you can't and shoul= d not be able to mess with the internals of code you didn't write: this = is similar to the principle of encapsulation in OOP, where you cannot mo= dify private properties of an object.

<= div dir=3D"auto">
Cancellation should be part= of the contract of an async function: it is safe, and most async langua= ges already implement it explicitly by passing a context or a cancellati= on token, the current approach of the RFC does it implicitly, which is a= lso fine.

Awaiting fo= r the completion of spawned coroutines should *not* be part of the contr= act of an async function: it is an incredibly easy footgun, as it's incr= edibly easy to spawn a coroutine meant to i.e. run until the object is d= estroyed, and then encounter a deadlock when the linked scope is awaited= for before the object is destroyed (even messier if cycles and thus the= GC are involved).

Languages like Kotlin that = do implement await on scopes have already realized that it is a mistake,= as can be seen by the many warnings against using await on a scope, as = I already linked in previous emails.

On the other hand, m= aking the same mistake described above, by cancelling a scope, will prod= uce a very easy to debug exception instead of a deadlock, easily fixable= by (warning the author of the library class) to use a new scope to spaw= n coroutines = within the object.

Awaiting a scope leads to deadlocks in = case where a separate scope is needed but not used, cancelling them lead= s to a simple exception.
Awaiting on multiple tasks can already be = done, explicitly, with TaskGroup.


Regards,
Daniil Gentili.

Hey&n= bsp;Daniil and Edmond,

I think I understand the= intention. Would it be better to instead of having ->awaitCompletion= (which feels like an implicit implementation of Awaitable without an ex= plicit implmentation -- which is the part that was bothering me), maybe = having something like ->joinAll() or ->joinOnCancellation()? That = way someone like me won't come along and wrap them in an Awaitable becau= se it looks Awaitable.

It also might be a good = idea to make specifying a timeout in ms mandatory, instead of a taking a= n Awaitable/Cancellation. This would also prevent people from simply pas= sing a "never returning" Awaitable thinking they're being clever.
<= div>
It also might be good to provide a realistic looking = example showing a "bad case" of how this is dangerous instead of simply = saying that it is, showing how a scope is not a 'future', but a containe= r, and preemptively mention TaskGroups, linking to the future scope (whi= ch it should also probably be listed there as well).

=E2=80=94 Rob
--8d407de2dabc43d4b3d5f6e0712d34a1--