Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129452 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 6DE8B1A00BC for ; Tue, 25 Nov 2025 11:51:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764071479; bh=+bO8UeE5VhaN3jrUj3Vbn4pkaV0MGa5GEUpRUlGx4T0=; h=Date:From:To:In-Reply-To:References:Subject:From; b=iYB/8CFnCjPf/QXuUQl4WdMpQZuYfwTvC86/j9xIaFhnjnmLjbEsts5DsDou+bqZI AqsGvyXpkgr9MSsLvDnzIVcAqcXA0Dy0KZO+fdxRdE6NgrN7ln1IQBGus+/wVWAX4Z 0tspQeAcsPY4mi8Di/au//dzqahWdgnC3dNgOM01XyihnJOOC5/r9hGfq646UQUlbO xuQXiOs09RG20gbcMH2zkPLQtE12Z/skrhZOqRAtoluDhzE/JgiJbUUHF6Wk/9+R8O Kx4++ipdseUa0h6yWoXLAWLOC6m3Z1ons3gD8UFQIDN+M4k4HQ3xv5hIQPAnqEIUBC VTfAGrREBQBiQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E7123180087 for ; Tue, 25 Nov 2025 11:51:15 +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_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,T_SPF_TEMPERROR 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 ; Tue, 25 Nov 2025 11:51:15 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 75F83EC00BF for ; Tue, 25 Nov 2025 06:51:10 -0500 (EST) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Tue, 25 Nov 2025 06:51:10 -0500 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=fm1; t=1764071470; x=1764157870; bh=+bO8UeE5Vh aN3jrUj3Vbn4pkaV0MGa5GEUpRUlGx4T0=; b=KXDcFF1f8gPFQBPbfmKHr9jrQj 1nK6XDwR31+JIrlKrKrbP3PyqtXx8DEwlDZt1MytaSFOSoqIRm4fB5cfFwSd6Lhi 8d25LRGrw8v43YspBVQGCiGyvQvCD5ezTtjikZ/GE0KN79DtWPnst9XzcaKdfs+d rm5hYrpk9bBzr/KTnF5w3FItpKdSx6uUynsyMlMWaiTf5hM08oQ+7g+EoJihCnow S6HQgU2Iq8L+7cn/HjaSI0AemcTYks3qGFkiS/ReBGomUncDwLNCeDpur0uiF/T9 /aF5k9Y/zLRdFYtXmnNcqcyZKJyPACsVZY6C7D9ckYlcgw1SAkcN7n0Al3nw== 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=fm3; t= 1764071470; x=1764157870; bh=+bO8UeE5VhaN3jrUj3Vbn4pkaV0MGa5GEUp RUlGx4T0=; b=OaLZi5AxO+9o68EhjSTgmxFpvWQsu/7b/FJMFkc+9oDmxzSarYl LGOIxUiX3VmMwfZQBLG5yU/AKJxmbsJAOj9oVnFT94v5rr1YOK3y+hbapMaIeu5/ iKl315f87YpPwVyWBP5LeLJVsL1wadfYsYRwGOUP0KQ/qXQgJwvxIM52QSzooLHu U/+qjKObGO+kqcArymXI3TuODiWIiMC8NeG85ky+bE3O9v2xZa5D7pjsDtU3c35d J2WR1tiRUuEhHrxgHNspBO+JywLzx4UpPnBvpEUCxpWx/k2GPJT/2ilqwwt/2KBl OUoU4HoO68cpfK4nX8w1LQv6L/uJRuw+oAw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvgedufeelucetufdoteggodetrf 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 E75171820054; Tue, 25 Nov 2025 06:51:09 -0500 (EST) 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: AT1NG5bj5VEw Date: Tue, 25 Nov 2025 12:50:49 +0100 To: internals@lists.php.net Message-ID: <1a31ee0e-cbfd-49df-baa6-99d27ae45fc4@app.fastmail.com> In-Reply-To: References: <92865666.4510.1763818506332@email.ionos.de> <329450798.8037.1763822426377@email.ionos.de> <9287c46c-bc63-4dd0-9792-0f9421959589@rwec.co.uk> <65869feb-d518-4de3-8c10-115e3ba7dce7@rwec.co.uk> <55149f3e-7ec7-4479-bd6d-2e7fe1b8edef@rwec.co.uk> <19693420-c091-49b7-b557-e09717239d9b@rwec.co.uk> Subject: Re: [PHP-DEV] [VOTE] True Async RFC 1.6 Content-Type: multipart/alternative; boundary=538cafc5c80b4b3bb6e1ca2b0a0c54f8 From: rob@bottled.codes ("Rob Landers") --538cafc5c80b4b3bb6e1ca2b0a0c54f8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Nov 25, 2025, at 12:03, Bart Vanhoutte wrote: > Op di 25 nov 2025 om 11:36 schreef Rob Landers : > > > > > > If we're going to have to recreate some of the most basic interfaces= to get async to work ... does it make sense to seriously consider colou= red functions? As annoying as it would be to refactor so much code, I th= ink we could realistically provide ourselves escape hatches by not requi= ring every function calling `await` to be async? > > >=20 > I have worked with coloured functions in PHP when Fibers were not > around and the developer experience is very bad. Before PHP 8.1; every > function I wrote would be coloured by either accepting or returning a > Promise (which is made worse by the fact there's no > generics). >=20 > Since PHP 8.1; I can use Fibers and implement a widely spread > Interface in an async way. Currently, if I want to use an SDK client, > the first thing that I check is `composer.json` to find out what HTTP > client it uses. If it accepts a PSR-18 ClientInterface I use a small > wrapper around ReactPHP's Browser that awaits a Promise and I'm set. > We've been talking about shared state and possible breaks in backwards > compatibility, but I must say that in reality it's not something that > I find being in the way very often. Like I've made it seem before, if > there's any serious breaks in backward compatibility (not the order of > log lines that might be different from the sync implementation) I > would at that point just document the change and release a new major > version of a library. That is a lot less painful imo than working with > coloured functions. >=20 > Best Regards, > Bart Looking higher up the thread, you'll see that Larry also proposed someth= ing similar. I'm not saying everything needs to be coloured. In other words, there is no "Promise" object that always needs to be han= dled. Adding an "async" to the function makes it return a Coroutine, tha= t can be awaited. This is a bit different than Generators where you can = only return a Generator. The return type stays as you'd expect it to be = if it weren't async. Then, when/if you call await on this coroutine, and we're not already in= a coroutine, it will spawn one for us, blocking until it returns. If we= are already inside a coroutine, then it blocks until the coroutine comp= letes. Then you have coloured functions when you want them, but can call them w= ithout having to change your code or "infect" your code with async/await= . Its literally just sugar over the currently proposed RFC, as you'd hav= e to return Coroutines and await them anyway, but this is actually more = type-safe. =E2=80=94 Rob --538cafc5c80b4b3bb6e1ca2b0a0c54f8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Tue, Nov 25, 2025, at 12:03, Bart Vanhoutte wrote:<= /div>
Op di 25 nov 20= 25 om 11:36 schreef Rob Landers <rob@bottled.codes>:
>
>
>= If we're going to have to recreate some of the most basic interfaces to= get async to work ... does it make sense to seriously consider coloured= functions? As annoying as it would be to refactor so much code, I think= we could realistically provide ourselves escape hatches by not requirin= g every function calling `await` to be async?
>
<= br>
I have worked with coloured functions in PHP when Fibers w= ere not
around and the developer experience is very bad. Befor= e PHP 8.1; every
function I wrote would be coloured by either = accepting or returning a
Promise<sometype> (which is mad= e worse by the fact there's no
generics).

=
Since PHP 8.1; I can use Fibers and implement a widely spread
=
Interface in an async way. Currently, if I want to use an SDK clien= t,
the first thing that I check is `composer.json` to find out what HTTP
client it uses= . If it accepts a PSR-18 ClientInterface I use a small
wrapper= around ReactPHP's Browser that awaits a Promise and I'm set.
= We've been talking about shared state and possible breaks in backwards
compatibility, but I must say that in reality it's not somethin= g that
I find being in the way very often. Like I've made it s= eem before, if
there's any serious breaks in backward compatib= ility (not the order of
log lines that might be different from= the sync implementation) I
would at that point just document = the change and release a new major
version of a library. That = is a lot less painful imo than working with
coloured functions= .

Best Regards,
Bart

Looking higher up the thread, you'll see that Larr= y also proposed something similar. I'm not saying everything needs to be= coloured.

In other words, there is no "Promise= " object that always needs to be handled. Adding an "async" to the funct= ion makes it return a Coroutine, that can be awaited. This is a bit diff= erent than Generators where you can only return a Generator. The return = type stays as you'd expect it to be if it weren't async.

<= /div>
Then, when/if you call await on this coroutine, and we're not = already in a coroutine, it will spawn one for us, blocking until it retu= rns. If we are already inside a coroutine, then it blocks until the coro= utine completes.

Then you have coloured functio= ns when you want them, but can call them without having to change your c= ode or "infect" your code with async/await. Its literally just sugar ove= r the currently proposed RFC, as you'd have to return Coroutines and awa= it them anyway, but this is actually more type-safe.

<= /div>
=E2=80=94 Rob
--538cafc5c80b4b3bb6e1ca2b0a0c54f8--