Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126824 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 AF4621A00BC for ; Tue, 18 Mar 2025 13:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742305838; bh=CEPiKJJOtVN0Jar28VATBAmqjxh6bxj7OdHLsa+Zalc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=fSiEO2hDjU9Fnk2EMFo2qF/uCLqy/3/I/gALEUozKmR2K/sAiRumsylVGYB+UZSjd ImdYFQLLURwTFpPyVG6sCuDwCx8/cXJ1K/K3xsvfyvXP2puOXwWPvF5iDpWVEFxiAh 7mXQQOwHUhYC4d5sn9RbhNmFYBm4JBd5JkTdeW6xqOBEaD5Q9mCb+WwS0ebnzleJKb VHDgM0zR157HahSVmyPx0Xe6NVR+ws8bPuFXgU6W4DGrgmYm18L+ApGpp2C6Bc4qtT HAEQbC+RLxR5Z9tQMfYn2nswQXWjF4sBetVIwg45OgSyxjMYaTDlhq6bW57YrInukX OSMc3JKWfWJeA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 82D351801E7 for ; Tue, 18 Mar 2025 13:50:36 +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-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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, 18 Mar 2025 13:50:29 +0000 (UTC) Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e63c966fe37so3905015276.0 for ; Tue, 18 Mar 2025 06:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742305980; x=1742910780; 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=2gXYv3A/yoMm/aP68OaaNF19cE+DXMxZCpTprl0wsdk=; b=a1ltM7Rsu9VcJCiVrIsLQJYwAvA89IBzfXk3fz+k21YA16zt5DtdY89oDxdeZTZDaz rKPybCRx+tZYIyHraZvXmLtJsK/0dCjqLdeHh0FSgUsgl9AE0KlxFa5BGG4MnsB3WlLp cF7jELo0uqXkWcWlg5k+2CfvwMfxxHd9qZ/Syf0IIDbbD5X8AkTLuAidxRD/jmOFjE9c CmiMJvX6BG4CZZ0rkknBih+XizTri6x9xgxkDRQiOHiw9IHpuC/5gx9YkfzGkl0F79Iq xz12Vk71/EDFkC+pVLS1t2ED9K6uAlbjUBlHujNLkkbyp1rXBGb3ZWGx0FF+1FOcq22s uptg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742305980; x=1742910780; 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=2gXYv3A/yoMm/aP68OaaNF19cE+DXMxZCpTprl0wsdk=; b=uDeOzDhm6Ed5Jk1XOus1RlfsrdoTPkfPaEf5dtDt6c1PGGIMBSKAofSeFIji0ZdV/m P/7EbfDa2tr7lGQfSM1qfFdMJpXnVMYLrb7XnRoamuLKzk/XBDUQv2qy+xdOuRYr9Oy4 UGjvBizEQdpKvdibJQkvq+r/tOI75JItCOZuS3VyyXJf49TI3+R0rVdF3uYM+g58Ep3C hwH9TI0llvdUQG9EUw3er7CQYnqMJszZFgxRy12GTHv89j7kjPsmcUpMaFwxqM/j5Jvm 2N/8VBTXv/CrUF9rSYlhI/YB8V4uP+Pxt5HoKTnF7qGgFRCzJv1/LEwnV5DqaTafCLum ntXQ== X-Gm-Message-State: AOJu0YwOwrscGlVFC+HI7hgN1wpgK4oiJNIOxiAaSzbpvCeEkgT/iW7S tXqr41EhV1VsTebqwRxRzhVYtwXJ/HE71p/gdTyypZiAx7F0MNTIF45ydAQNyWaI0XcGuZj4PN6 YlQSBirp6Xs97rnEllx+DbCkc2nLmK3HWh/M= X-Gm-Gg: ASbGncub+KJCiGRUZQY6RKkK2wQdO5FZMJeFaOSIicz/oc8SkEvoFsFY/tmXOyMaVHj FAPIqYlutEAnlfbp1ZnhJeLHG7nb8UErnfofzV5IJKrPSTcxGGdkO5F+HtJZgZXcKCoxmUepNYR TIvAdeV9WVNDi75eqaLEqxJZ8Qug== X-Google-Smtp-Source: AGHT+IEjXNwpSVYj8Yg0gnDW253R2G9BG9A1QWS30w8DMJmAoa8Iga3mIp57nSLXwOlOds5ZE7Q41iPp91HIJ5vdDwY= X-Received: by 2002:a05:6902:2581:b0:e60:8734:64df with SMTP id 3f1490d57ef6-e64c0e1e1c6mr4761717276.36.1742305980402; Tue, 18 Mar 2025 06:53:00 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <72bd5401-53a9-409f-ad45-687333401961@rwec.co.uk> In-Reply-To: Date: Tue, 18 Mar 2025 15:52:48 +0200 X-Gm-Features: AQ5f1JqmYHWKWOmflJNr84d71b_7ZQ7P9hGlW7-ocaCtBFxPb_hUsryoEE4UmkI Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000000d533806309e39d3" From: edmond.ht@gmail.com (Edmond Dantes) --0000000000000d533806309e39d3 Content-Type: text/plain; charset="UTF-8" Oops, I made a mistake in the logic of `Scope` and coroutines. According to the RFC, the following code behaves differently: ```php currentScope()->spawn ... // This coroutine belongs to the Scope spawn ... // This one is a child coroutine ``` I was sure that I had checked all the major edge cases. Sorry. This will be fixed soon. P.S. + 1 example: ['timeout' => 5]]); return file_get_contents($url, false, $ctx); } function fetchAllUrls(array $urls): array { $futures = []; foreach ($urls as $url) { $futures[$url] = (spawn fetchUrl($url))->getFuture(); } await currentScope(); $results = []; foreach ($futures as $url => $future) { $results[$url] = $future->getResult(); } return $results; } $urls = [ 'https://example.com', 'https://php.net', 'https://openai.com' ]; $results = await spawn fetchAllUrls($urls); print_r($results); --- Ed. > --0000000000000d533806309e39d3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Oops, I made a mistake in the logic of `Scope` and co= routines. =C2=A0

According to the RFC, the following code behaves di= fferently: =C2=A0

```php
currentScope()->spawn ... // This cor= outine belongs to the Scope
spawn ... // This one is a child coroutine
```

I was sure that I had checked all= the major edge cases. Sorry.
This will be fixed soon.=C2=A0=C2= =A0

P.S. + 1 example:

<?php

declare(strict_types=3D1);

use Async\Scope;
= use function Async\currentScope= ;

function fetchUrl(string $url): string {
$ctx =3D stream_con= text_create(['http' =3D> ['timeout' = =3D> 5]]);
return file_get_contents($url, <= span style=3D"color:rgb(0,51,179)">false
, $ctx);
}

func= tion fetchAllUrls(array $urls): array
{
= $futures =3D [];

= foreach ($urls as $url
) {
$futures[$url<= /span>] =3D (spawn = fetchUrl($url))->getFuture();
}

<= span style=3D"color:rgb(135,16,148);font-style:italic">await
currentScope();

$results =3D [];

foreach ($futures as $url =3D> $future) {
$resul= ts[$url] =3D $future->getResult();
}

return $results;<= br>}

$urls =3D [
'http= s://example.com',
'https://php.net',
<= span style=3D"color:rgb(6,125,23)">'http= s://openai.com'
];

$results =3D await spawn fetchAllUrls
($urls);
print_r($resul= ts);

---
Ed.
--0000000000000d533806309e39d3--