Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128935 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 01F011A00BC for ; Thu, 23 Oct 2025 16:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761237654; bh=yH28pIG9v4e9+ciQ32HNa+xjQx1lK/M7XI8o8LwRw1M=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=fs1hJ5hojkc6+d1qgiu1TbsbIHbXLrSraPAoIqHhRkHE9KlQayXx/fYO4UW5qqvjQ 7sFDT9jgfhPwvdlBHz0xePNYuAI9hsRvTfvB6b5AuApKYxcvP+EDHnrPeIpMOaLdQJ 0zYM0Wnz+Hlp0AW+YBBCq/8s7IFMym/93VKGrn+/xlTfYBJAel6mfNtANENWuHzfqV YTy05ZN8i5eLfR7Iwgb3tKs3CQ5xvgtHZwYcz2lVyt3c4MztORr4sXyWsByahczImv tRMpDIaNK7wojyoDzWPt4/2LaeLXwqNzK4GaSXkWR0AaB+jPyCQW4mapm7gWGMx+X9 6STAoj34jI43A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C9EDA1801DC for ; Thu, 23 Oct 2025 16:40:53 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from nebula.zort.net (nebula.zort.net [96.241.205.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 23 Oct 2025 16:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zort.net; s=zort; t=1761237647; bh=yH28pIG9v4e9+ciQ32HNa+xjQx1lK/M7XI8o8LwRw1M=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=iDmsOP4+fw9NQfvswym9BDeOkoFtV0XaKWiRkmV+uWNcIhahOgnbdMmHxnXaJaSt2 KX7/s+zFgBslEUJHWXdg1k8s7mFqgD/f8MY9bra9pYsTrzF8rPRaOeUPiRNQfprG7w dr3F/xWgx6xM8w+MJeOzqB0D2/NPkQngZDUCGsYo= Received: from smtpclient.apple (pulsar.zort.net [96.241.205.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nebula.zort.net (Postfix) with ESMTPSA id D53F01300503; Thu, 23 Oct 2025 12:40:47 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 In-Reply-To: <51a4f8e0-2dbe-444c-aeda-162020c022c5@app.fastmail.com> Date: Thu, 23 Oct 2025 12:40:37 -0400 Cc: Aaron Piotrowski , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <0e4e39d6-9cc9-4970-92e0-2463143b4011@app.fastmail.com> <37180d8d-85b4-49a3-a672-334bf4329470@app.fastmail.com> <2f8524a7-dea2-4fbf-933a-c538d3706253@app.fastmail.com> <151800a7-1094-49bc-8e43-c593a74741af@app.fastmail.com> <51a4f8e0-2dbe-444c-aeda-162020c022c5@app.fastmail.com> To: Edmond Dantes , Rob Landers X-Mailer: Apple Mail (2.3826.700.81) From: jbafford@zort.net (John Bafford) > On Oct 23, 2025, at 04:18, Rob Landers wrote: >=20 > On Thu, Oct 23, 2025, at 09:59, Edmond Dantes wrote: >>=20 >>=20 >> I=E2=80=99d like you to have the full information necessary to make = an >> informed decision. >>=20 >> There are two or more channel objects that need to be awaited. How >> should this be implemented? >>=20 >> Currently >> ```php >> [$result1, $result2] =3D awaitAny($channel1, $channel2); >> ``` >>=20 > As for which one I'd rather have, I'd rather have the one where my = examples hold true: >=20 > assert(awaitAll($a, $b, $c) =3D=3D=3D [await($a), await($b), = await($c)]); >=20 > It's clear what it does and that it is just a shorthand. When that = fails, we have issues. >=20 > =E2=80=94 Rob Just to add to this, in Swift, a Task (the analogue to this proposal's = Coroutine) can emit, exactly once, a value or an error (exception). = Attempting to read its value (or error) multiple times gets you the same = value back. This is very handy in memoization patterns. In this example, multiple readers can call getImage() with the same id = and get a value, regardless of whether they're the first (which kicks = off image loading), whether the image loading has completed, or whether = the image load is still in progress. (Technically, one could omit the = LoadingBox wrapper entirely, but that would cause the Task to persist = after it's completed, and that's a more expensive structure than a = simple enum.) ```swift private enum LoadingBox { case inProgress(Task) //Task case ready(T) =09 var value: T { get async { switch self { case .inProgress(let task): return await task.value =09 case .ready(let value): return value } } } } private var imageCache: [ImageId : LoadingBox] =3D [:] func getImage(_ id: ImageId) async -> Image { if let cache =3D imageCache[id] { return await cache.value } let task =3D Task { ...load the image... } imageCache[id] =3D task =09 return await task.value } ``` Ultimately, I would want to be able to write code such as this in PHP = (with the generics, of course, but I'm not holding my breath). If coroutines sometimes return single values and sometimes return = multiple values, it becomes much harder to write a generic async = cache/memoization system, because you can't indicate via the type system = that a single value is expected. -John