Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126881 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 74F841A00BC for ; Thu, 20 Mar 2025 21:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742506738; bh=LZN/LIIZczwOBov0eE9XWKsegJl60urz/gyUusCbJQM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=JDw2gNiJmHXjGoM9Ja/Ae7v4PyUSMuvRrd6MRpkPVal/5dE0NMMygXhhKsijyPmSo FIEvsE089V5cw0BC9wH+POs6WNF2BDq9jBCQoexXcwZLOUCwKeZXUvamYdA7Gxjvf7 Yl57JVxGqIK0wsTDcGw1by0Btcgf8No/qwZ6XPafubGcBXMghWRcCmJv1/stXor3Ic 9d8j2FnV69YzWhCARZ437DgSiqKAAO1ag+n79sJQ3v1CAdRWwjAzXFSD6h3nHcgN7h Kkz0dXQtNSABg0fpD1V4OVKAEeww42YixK9cF/D9U429eCyOnOp/ZRXYXobdY7HzvE M1gajc6y0gZ/g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 65C52180068 for ; Thu, 20 Mar 2025 21:38:57 +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, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.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, 20 Mar 2025 21:38:57 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id 3ADB41140099 for ; Thu, 20 Mar 2025 17:41:27 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 20 Mar 2025 17:41:27 -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=1742506887; x=1742593287; bh=fVtPPNudxoLeCskZaGwP+YXEb7WjGQtq0zk2nq242NY=; b= lrdJwyW+yXn/zKxf5RGVEcr97i09vb7A2/MnDrmuTZqqji+CraGQIRrbviIW79bR 9RY6kVlJ5Z5TW1A+0pDMlKpgSSnA/t6LOsm0RK00k5PXos5w0Hj8c8W0yueV0tr2 5YxyIvp6aC8k4ttoBAEk55AXCAs9AMb6Vb4lH4MxK65SbnzBKNlOpp0zwio60U2m y5Yua+3gjLp7Um9U51iph7iJUzB993FF4iv/u7QM8aqE8ZjveJ9jmZ3ywG1rDat7 S9AobQ2Dy9Nh6tX+CEx/AyVWjV4TX98L25b9+gBpHee6rqGWq5xc/VZGYHasJKdH B6A8s9y38gztsX34U04t+Q== 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=1742506887; x=1742593287; bh=f VtPPNudxoLeCskZaGwP+YXEb7WjGQtq0zk2nq242NY=; b=Dw23r/loXkJd8W05j Ffv1wQr/OI1dfmsp74U+zYSkeR09xtBI17kSY3fSM4DVdIk4GruIWsSnWAnH/Bw+ UtYhHL1NrTxjIPNtEZ9i3qFw9aEGZXPk8annNx9s7iN/VZycS9cL3mMLxWcgXeci IIapJlOVDuU7AD8w4x21KdQ1vFy64b8kNj4I3Ge5thVwJXNFDnfDAlTa1pgtBdLH 9V1dqjV2KDlIgmkID7QeIu5mNSIdzfrg4Hb4AJS9Li7I/SV6e4DtkOsyY/xBbB0+ 75orxa74DriE8Wnyh6uA5XUD9WVbvGkXADn8sI4RbOvXIOHOTap84R8VsHrBntow CW+Fg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeelfedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkff ggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhm ihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqe enucggtffrrghtthgvrhhnpeffkeevudffuddvheejvdefkeelfedtudegfeehjeduheeg ieduffeggeegveefheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthht ohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslh hishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 20 Mar 2025 17:41:26 -0400 (EDT) Message-ID: <4669e994-fe7f-4c3b-9920-ef6ac0118f1f@rwec.co.uk> Date: Thu, 20 Mar 2025 21:41:25 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: internals@lists.php.net References: <6987D912-CE46-4145-A8CE-732CA590A522@rwec.co.uk> <2F013672-9937-4AB1-BC46-86F3D342BE6B@rwec.co.uk> <743c84d4-28db-4f68-80e5-3cad2dac6e68@rwec.co.uk> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 20/03/2025 11:01, Edmond Dantes wrote: > > > > Specifically, what is the use case where syntax #2, "spawn function_call" is not good enough, leading us to add a special case into the grammar. > > > Additional parentheses around + parentheses after. That is, (closure)(). The goal is to get rid of this construct. Again, that's the *how*, not the *why*. We only need to "get rid of" the parentheses if there's some reason to type them in the first place. > A safer approach would be to implement only syntax 2 and consider the alternative option only if user feedback suggests it's needed. Sounds like a solution without drawbacks... This is pretty much where my mind is going - if we can't articulate an actual reason why "define an inline closure and pass it to spawn" is so common it requires special implementation, then let's keep it simple. > ```php > spawn fn() => [file_get_content(), file_get_content(), file_get_content()] > ``` > > At this point, I haven't been able to come up with examples where such a closure would actually be convenient. > Maybe this use case will emerge later. I was thinking of something like this maybe: $contentFuture = spawn ( fn() => file_exists($filename) ? file_get_contents($filename) : '!! no such file !!' )(); Or even: spawn ( fn() => do_something( fetch_something($input) ) )(); Which looks like it would be equivalent to this, but isn't: spawn do_something( fetch_something($input) ); (It calls fetch_something() inside the coroutine, rather than outside it.) If anything, this seems like a better candidate for a shorthand than the full closure syntax, because we already have the rules for automatic capture and automatic return available to reuse. Maybe it could be as short as this: spawn => do_something( fetch_something($input) ) ); From longest to shortest: spawn ( function() use($input) { do_something( fetch_something($input) ); } )(); spawn function use($input) { do_something( fetch_something($input) ); }; spawn ( fn() => do_something( fetch_something($input) ) )(); spawn => do_something( fetch_something($input) ) ); Or, if we get Pipe syntax, it could end up like this: spawn => $input |> fetch_something(...) |> do_something(...); Again, though, this could easily be added later when a need becomes visible, as long as we don't do something weird now that closes the door on it. I suggest we leave this sub-thread here; there's plenty of other things to discuss. :) -- Rowan Tommins [IMSoP]