Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126689 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 qa.php.net (Postfix) with ESMTPS id 09C8C1A00BC for ; Mon, 10 Mar 2025 11:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741604252; bh=FQ/Le1NvL/EKk6e5QWe98UbYKe5QdpvkJ1lmrkM2FeA=; h=Date:From:To:Subject:In-Reply-To:References:From; b=b38q741kFNrVXf/SMToigawnguXXfwnv1R0/jbAeDcF9MHBeiXf++PnJD2GUYj1f7 PIoeAj/PRdJYXPlKmUjCeSBD9UQsUDEvuvfnUAAIorq6fGwUDUnrYQEt7e/STP7JW6 tmYTSg4CR/Ceio5zsIqnFIk2epylAm6IWVn09Zmc9VC6PcrdpVxCYOsWFXde7xAhQA 8YRCuwVPdlUIFkAtaaS/9gymnjlMSzCP4nqV2YKNzMd0stOR+F6CCb/+4ca6RbwSRO kk0Zf3Oc3Gv2oUxXs74ucwYJXrUtw/VoIV5wWCj6ksQVs6IAyKdbCYDEdLNnQaZWf0 +ygvtO4E6yEKg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 747F3180081 for ; Mon, 10 Mar 2025 10:57:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 ; Mon, 10 Mar 2025 10:57:31 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 8E5051382D57 for ; Mon, 10 Mar 2025 06:59:59 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Mon, 10 Mar 2025 06:59:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding: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=1741604399; x=1741690799; bh=cWzZhzDb4rkS4AtG1tIvKsE3b05tApLVXYWmJ9+8ZYY=; b= cYtjjXqFlHecqEXMBJQhEpA1czYMBd+y7wLzeNSL7wCUtMupiltT5cU9wzFV54E4 akSuQ7seumEDL+PQWVQsolXbhFQpJgk9oC+gDz72st9t8Bm9x8cSSGmpioxS1VPS hPznq/xU6W4gsZgrO/FLj1lLykVh8IHeoLolsdTV3IWrF+JiIvGRqOdY8H1gMwuZ OhhhwoBOJWBs6d2U7BI4HNd2RQSi5j5Bqd50iZqjQVeEZ1uJSnMGSnBrsZ7fdW1H +sELpBBNUgG/AMd19rbrSdk1+0T3Gu5ac8yNsdoplLICYaUMncrzFA+pFHX1nKHB hVRhKHrD7xLAKSZ67BSsaA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=fm1; t=1741604399; x=1741690799; bh=c WzZhzDb4rkS4AtG1tIvKsE3b05tApLVXYWmJ9+8ZYY=; b=QkevY+UVNVGo+J4D0 nWok2x59/8d1vQUIqSnufjNRK0pRnrq5GWaD8UGTas4MEmz8TGrzUPaay4ck3Ywb zUz/JL+YyayL+91T3KYOGq8tb4955rD+rkRZREX57ZOXlGlBllhG/NxSfpNVzG3d b4zRWaDbwcpK7xDMEUd7PfRW/XUbcY/YVoJrNPjSOToxouZZvVP4DBMwfHwRXNSi Kt/5raxtJws0KAyrlzGDpD/yiDwLxbShgvzaIYblFhV//V/D6gNVj88xb9QTmlTp +1RWxLYKWupVuZMPCAkpUbBmNCg+7aSjOjDWsFjXmSdx2gXy3HCNbphWvYTqCbK1 N+rjQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudeludejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhf fvufgfjghfkfggtgfgsehtqhhmtddtreejnecuhfhrohhmpedftfhofigrnhcuvfhomhhm ihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqe enucggtffrrghtthgvrhhnpeehleffteeigfevudetfedugedtudevledugeeugeelheei hfehgfdtkeevvefgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthht ohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslh hishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 10 Mar 2025 06:59:58 -0400 (EDT) Date: Mon, 10 Mar 2025 10:59:56 +0000 To: internals@lists.php.net Subject: Re: [PHP-DEV] Re: PHP True Async RFC User-Agent: K-9 Mail for Android In-Reply-To: References: <1b6a5b3b-be9b-4e46-9cc6-b8b7f57b8494@app.fastmail.com> Message-ID: Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 10 March 2025 03:55:21 GMT, Larry Garfield w= rote: >Support for nested blocks is absolutely mandatory, whatever else we do=2E= If you cannot nest one async block (scheduler instance, coroutine, whatev= er it is) inside another, then basically no code can do anything async exce= pt the top level framework=2E To stretch the analogy slightly, this is like saying that no Linux program= could call fork() until containers were invented=2E That's quite obviously= not true; in a system without containers, the forked process is tracked by= the single global scheduler, and has a default relationship to its parent = but also with other top-level processes=2E Nested blocks are necessary *if* we want automatic resource management aro= und user-selected parts of the program - which is close to being a tautolog= y=2E If we don't provide them, we just need a defined start and end of the = scheduler - and Edmond's current suggestion is that that could be an automa= tic part of the process / thread lifecycle, and not visible to the user at = all=2E >This function needs to be possible, and work anywhere, regardless of whet= her there's an "open" async session 5 stack calls up=2E > >function par_map(iterable $it, callable $c) { > $result =3D []; > async { > foreach ($it as $val) { > $result[] =3D $c($val); > } > } >return $result; >} This looks to me like an example where you should not be creating an extra= context/nursery/whatever=2E A generic building block like map() should gen= erally not impose resource restrictions on the code it's working with=2E In= fact as written there's no reason for this function to exist at all - if $= c returns a Future, a normal array_map will return an array of Futures, and= can be composed with await_all, await_any, etc as necessary=2E If an explicit nursery/context was required in order to use async features= , you'd probably want instead to have a version of array_map which took one= as an extra parameter, and passed it to along to the callback: function par_map(iterable $it, callable $c, AsyncContext $ctx) { $result =3D []; async { foreach ($it as $val) { $result[] =3D $c($val, $ctx); } } return $result; } This is pretty much just coloured functions, but with uglier syntax, since= par_map itself isn't doing anything useful with the context, just passing = along the one from an outer scope=2E An awful lot of functions would be lik= e this; maybe FP experts would like it, authors of existing PHP code would = absolutely hate it=2E The place I see nested async{} blocks *potentially* being useful is to hav= e a handful of key "firewalls" in the application, where any accidentally o= rphaned coroutines can be automatically awaited before declaring a particul= ar task "done"=2E But Daniil is probably right to ask for concrete use case= s, and I have not used enough existing async code (in PHP or any other lang= uage) to answer that confidently=2E Rowan Tommins [IMSoP]