Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126692 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 10ECD1A00BC for ; Mon, 10 Mar 2025 11:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741606469; bh=5AiuUm6fLbjJyGlxHQsVMcR9Yc5oQ4ae+csMUu49qQY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XCaYCAgt6nswboHCqwuVkth7NqJnkJcB4mcUtFS3WMKmJ2hEOcDzjAD0z/L8vVxEG ffc0SLCqT61b5+b5HfS1KFW11uhfQw79/CoY1l4/e4H+I5stg2yUR0wYXg2YctRkZ1 oalIk5SCC+yUofqMcwHyqyNDns0T8Ki+2Cq/SeoX5uPNo1JyIzqkkdHHjlu4+yG1Ow JPOmgpHZ7r7FbVghlD8Ye62B5yVNakLtkzmM071SZFmi99XQLXnVc+7diPskuvxXQj CZdgLP66ZxFypHw3aDpb6TbpDNKcdZ/54/sSxSO6b4CuEbTptLuUgfzZ/hMk0d/cug +wxlbb/Ier2qw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9BE0318004B for ; Mon, 10 Mar 2025 11:34:28 +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=-1.2 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (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 11:34:28 +0000 (UTC) Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e60cab0f287so2778217276.0 for ; Mon, 10 Mar 2025 04:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741606622; x=1742211422; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MKUgMWzjELte3oSlv6ovk7iO4Br1M4Tp5Q5xiD/+KQ0=; b=NhRpFXkaCZLB2y+fNmr5k4Wujv7H7K0JKv4olWrd1XrYtiEhoWN/gTLrBdOQsy1Iqr Gvfgs3mcsEYY9jpiAB61RaLiwLFDN9UPL28hq/Xw0sstz9iktx+gX/gXsR5F60aBZbXF doq9Rfn5RGNblHz2kt41XiBFNx7ccROY4PCirzL+ovL32QawE0BKFao9VNOGeUH/Hi9c gOPe3WnmNh3XrCB3qeCKdnhPczi3yWYOp1QqHxUwsBKHy2GVM5EHtVHOlnhJsd6FChDa RSEmawmhe7m6zPm0KXfL9RSkSoESQTRPWgRrbi0qPzS5IcSzNF/FABseTfe4eInj+L8E e3Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741606622; x=1742211422; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MKUgMWzjELte3oSlv6ovk7iO4Br1M4Tp5Q5xiD/+KQ0=; b=VxN+RPnokW1EsOmRUEw+ylv22UIEYV7jluEHvsRxnrYdYk6qMBhfkCUU4eRoRq3PVJ AaEqaVEi6cdmzOZ4jdq66+45TWECUfvY50UwYQAMFHor3fSJpgoIqv5cL82xatkofsJd KRrpfg5Pp3mSjdBA//zGBGqyx+0BjGz2opYTgMOFg0BlkQ9adbCdsxJ/lHUSYnun84/o Zf7gR3+mt6D78tuVbUFXYx0vSaQ/te5Rq5wWI1Mv0bdjdIuQdbLpTkGogKvjEfYbUdoX UHbInwWwij3NPNkuYBqHIui/z6L1fv+5RQv8O23a5pibexFE4keg6k4NM21PTFqAZftY rVZQ== X-Gm-Message-State: AOJu0YxvtCdBWQ3Chj7kjCv6+O4rxq1pfH1sH1+nAwz6HVbqSCW8bxd4 1++arMRGqrjzzfq/15+PrlQV5TDY6ekiMo8qCHb7vW8OSPSw8TVOyxzB1TXLIOadFJemGGRqxTH +2p38d08wTyzP+DaU+sHSerWs3M1lRL//BY8= X-Gm-Gg: ASbGncu0idPEk+iHVKXpkB7XysYeYsqMka7JOrjjaHUN2lS7fmkg9Jb9P3ifJLDPh+e sPEPW6F/E/qL45NH819dhMjPjlp3aNswd3c5gPCVgWpMHORij7u/dSSa1gCn5brGxUx6cUxItjd xVbLl8SdpXv24CmUBjAmS9IWb5I+iQ3qGdDGFa X-Google-Smtp-Source: AGHT+IFE4aljh0EilY+9F7eigfagzkWfR6Vw2Lf4dT0cfwgqU32PVp2gsd6Jx7HX4c67pl2oIozGatY56qDItgAl1J4= X-Received: by 2002:a05:6902:2d8e:b0:e63:5e4d:121a with SMTP id 3f1490d57ef6-e635e4d1464mr11345676276.21.1741606621995; Mon, 10 Mar 2025 04:37:01 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <1b6a5b3b-be9b-4e46-9cc6-b8b7f57b8494@app.fastmail.com> In-Reply-To: Date: Mon, 10 Mar 2025 13:36:50 +0200 X-Gm-Features: AQ5f1JoCY06JzefXwCrxndm46X_Y1zhNBuWIP-VBhO2zxO_NtJk94q1CU9C9Vpk Message-ID: Subject: Re: [PHP-DEV] Re: PHP True Async RFC To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000000aeead062ffb64b4" From: edmond.ht@gmail.com (Edmond Dantes) --0000000000000aeead062ffb64b4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable >function par_map(iterable $it, callable $c) { > $result =3D []; > async { > foreach ($it as $val) { > $result[] =3D $c($val); > } > } >return $result; >} If the assumption is that each call can be asynchronous and all elements need to be processed, the only proper tool is a concurrent iterator. Manually using a foreach loop is not the best idea because the iterator does not necessarily create a coroutine for each iteration. And, of course, such an iterator should have a getFuture method that allows waiting for the result. Yes, Kotlin has an explicit blocking Scope, but I don=E2=80=99t see much ne= ed for it. So far, all the cases we=E2=80=99re considering fit neatly into a frame= work: 1. I want to launch a coroutine and wait: await spawn 2. I want to launch a coroutine and not wait: spawn 3. I want to launch a group of coroutines and wait: await CoroutineScope 4. I want to launch a group of coroutines and not wait: spawn 5. I want a concurrent iteration: special iterator. What else are we missing? --0000000000000aeead062ffb64b4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>function par_map(iterable $it, callable $c) {
>= =C2=A0 $result =3D [];
>=C2=A0 async {
>=C2=A0 =C2=A0 foreach (= $it as $val) {
>=C2=A0 =C2=A0 =C2=A0 $result[] =3D $c($val);
>= =C2=A0 =C2=A0 }
>=C2=A0 }
>return $result;
>}
If the assumption is that each call can be asynchronous and all= elements need to be processed, the only proper tool is a concurrent iterat= or.=C2=A0
Manually using a foreach loop is not the b= est idea because the iterator does not necessarily create a coroutine for e= ach iteration.
And, of course, such an iterator should have a getFuture metho= d that allows waiting for the result.

Yes, Kotl= in has an explicit blocking Scope, but I don=E2=80=99t see much need for it= . So far, all the cases we=E2=80=99re considering fit neatly into a framewo= rk:

  1. I want to launch a coroutine and wait: await spawn
  2. I want to launch a coroutine and not wait: spawn
  3. I want to launch a group of coroutines and wait: await CoroutineS= cope
  4. I want to launch a group of coroutines and not wait: spawn=
  5. I want a concurrent iteration: special iterator.

What else are we missing?

--0000000000000aeead062ffb64b4--