Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126830 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 D01D41A00BC for ; Tue, 18 Mar 2025 21:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742333657; bh=ammiqjpiscv/C6lxll4o+f6wn7aUQy776UGcbtnr8F8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=grYFqYumYOeVFJTKD6g3bl6ysYIbYEkREvg+mq72UVW7Ar9KqHKuaSuYzIeM6IQme 4T3sKmsyRpaIAAqo/H26bWlyxUIFACyGO/OeizwkdSshPHjV4hhwDbsupl+PgFkJ4q saqhvrq/SXmS/xtB6/8CK7wo9bO/1EhCDT0QN9THrurXamX3Chc69+JS7DRZHzLSjP yZNr4XuJwKpIyfAqeNK5tiMYCSZ5ylGfkb7OdM8Oc41851BywRqWKKcshPRRqNxSkP nZdeHpF1bVA7g51xwe0sDaQMQXJ/JYZMunkJaIi4WiJSsgB2sYF5SBPJBTJTRt93Pg qms9LT3x9e5fw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 67CA7180071 for ; Tue, 18 Mar 2025 21:34:16 +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 21:34:16 +0000 (UTC) Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e5dc299deb4so5946799276.1 for ; Tue, 18 Mar 2025 14:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742333807; x=1742938607; 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=3FKZS67ZP3j2z717OeEhOEAzLgvKkKaSwe4qLNOO97s=; b=Abyx+39+SJxYYTimXxsTZGhuWG1UUoQuP5faTwJFsK0WR2P7l58x+5drU3vN/qbC42 ZKqPEHvFfAoz9Q71ocO6HbDlvtyYwo/oYahDp4Lk13iziHY2wfpCIRruDlkiYFwNFeue TdYH1hV3zVCyYIyXqAb+tt80XrKQu1hBcCRmA4Nhuz240WUaG4RNjKwGuc5e+vdxgHgs DhFm0I2tmNEKtQrmBVg4+t5SuMsCD/ZuEKFuuumSbBBsScUCHrhCCcWk2wJpvuj2BX6A YIg10Y+/gZl0sBkfCF0JeMTPdNaEyPDZlpePMsgqC6Juw/5j3oaWFlEy/IOTEDN9mNur 2bsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742333807; x=1742938607; 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=3FKZS67ZP3j2z717OeEhOEAzLgvKkKaSwe4qLNOO97s=; b=a/cz0YTh7Ho1WhAgL3cE9G4wYAHIdAII1ciBGekbvKfUK7wfNCAwipICAGw3IQS/vM V1218DKyWZSi4EbZzmr6t7fhlicdH1qbx4FYNGYf0C0cil1TIRDX5K0NdGxy7L7KPOEQ YHSppxTZB0Lss0TFdpeHzJul424qJF8saRT1sGwvb9oiCttZ9qZ1cRCI0bylUnJjITE5 VkrgpK0eSE5YH2DAb+UpVa1c1MLIoF2v6huoNOuSxP7zDQlI32Bzvu/wihwnIoBaKiff W+wyC7ruz3A1U+im8etTLinV3mDf7DiMTLN1CeIKXjrpMUhUapZhn6Vq8EsC+Z4yuvSf NA9g== X-Gm-Message-State: AOJu0YweBfGnja/4Ybx0yGK1tSeq29J+M5kJc0RaQiKq+FnqueSVS3hh dFevaTQO9WIZ9R/MjJDwfc6HwPiivGMaHCEG0+nject1zIVQXRxwCpR7UR3+HYoZ5zkt4Vi0Qzy NJE0LsCe0tPBDN5HlF+gBUasfX1sfZH7uYuE= X-Gm-Gg: ASbGncs3gOD3V+FnmUOHDkEXiU/B0LUal2zPejOEWoQ0W9tUm22aTNRXFt25dhVQZFv cjcfxzrWSBY3/EGh2c8kwepMU3ntXy6aYPeWSFVpG7zl6sMuuGJakuLwma37aoa09dwiiWCp1uh PK3/RTv5pnfnr/nQsvCYr4AcVYENR1H41Q8XYR X-Google-Smtp-Source: AGHT+IGActCurz0m3jTijpsm0p/aCc2w/I59Hs9Y1ZA8Ajtzs0T1X2uJstGVVztqI4c4ZYEtlqdfJfikO/EmkOqkxHo= X-Received: by 2002:a05:6902:1892:b0:e5d:f878:7b50 with SMTP id 3f1490d57ef6-e667b3dad01mr519730276.23.1742333806722; Tue, 18 Mar 2025 14:36:46 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 18 Mar 2025 23:36:35 +0200 X-Gm-Features: AQ5f1JqA-AR5UQmZlxwLMWZosffweu380L2q_Uw0LUmcgHpL20ZCPzESHzbWXys Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000a146ca0630a4b3f2" From: edmond.ht@gmail.com (Edmond Dantes) --000000000000a146ca0630a4b3f2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Continuing the discussion from [[PHP-DEV] PHP True Async RFC - Stage 2]( https://discourse.thephp.foundation/t/php-dev-php-true-async-rfc-stage-2/15= 73/16 ): [quote=3D"Crell, post:16, topic:1573"] // Creates an async scope, in which you can create coroutines. [/quote] Yes, I understand what this is about. Here=E2=80=99s a more specific example: launching two coroutines and waitin= g for both. ```php $scope =3D new Scope(); $scope->spawn(fn() =3D> ...); $scope->spawn(fn() =3D> ...); await $scope; ``` The downside of this code is that the programmer might forget to write `await $scope`. Additionally, they constantly need to write `$scope->`. This code can be replaced with syntactic sugar: ``` async { spawn ... spawn ... }; ``` Am I understanding this correctly? Does it look nice? I think yes. And at the same time, if the closing bracket is missing, the compiler will throw an error, meaning you can't forget to `await`. That is the only advantage of this approach. Now, let's talk about the downsides. ``` function task(): void { spawn function() { echo "What?"; }; async { spawn ... spawn ... }; } ``` Let me explain. You can write the `spawn` operator **outside** the `async` block. Why? Because **nothing** can prevent you from doing so. It=E2=80=99s simply impo= ssible. After all, the function might already be executing inside another `async` block outside its scope. That=E2=80=99s exactly what happens an `async` block is essentially always = present as soon as `index.php` starts running. It is necessary to determine whether this syntax truly provides enough benefits compared to the direct implementation. I will think about it. --000000000000a146ca0630a4b3f2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Continuing the discussion from [[PHP-DEV] PHP True Async R= FC - Stage 2](https://discourse.thephp.foundation/t/php-d= ev-php-true-async-rfc-stage-2/1573/16):

[quote=3D"Crell, po= st:16, topic:1573"]
// Creates an async scope, in which you can cre= ate coroutines.
[/quote]

Yes, I understand what this is about. = =C2=A0
Here=E2=80=99s a more specific example: launching two coroutines = and waiting for both.

```php
$scope =3D new Scope();
$scope-&g= t;spawn(fn() =3D> ...);
$scope->spawn(fn() =3D> ...);

aw= ait $scope;
```

The downside of this code is that the programmer = might forget to write `await $scope`.
Additionally, they constantly need= to write `$scope->`.

This code can be replaced with syntactic su= gar:

```
async {
=C2=A0 =C2=A0 spawn ...
=C2=A0 =C2=A0 spaw= n ...
};
```

Am I understanding this correctly? Does it look n= ice? I think yes.
And at the same time, if the closing bracket is missin= g, the compiler will throw an error, meaning you can't forget to `await= `.

That is the only advantage of this approach.

Now, let'= s talk about the downsides.

```
function task(): void {
=C2=A0= =C2=A0 spawn function() {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 echo "What?&= quot;;
=C2=A0 =C2=A0 };

=C2=A0 =C2=A0 async {
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 spawn ...
=C2=A0 =C2=A0 =C2=A0 =C2=A0 spawn ...
=C2=A0 = =C2=A0 };
}

```

Let me explain.
You can write the `spaw= n` operator **outside** the `async` block. Why?

Because **nothing** = can prevent you from doing so. It=E2=80=99s simply impossible.
After all= , the function might already be executing inside another `async` block outs= ide its scope.

That=E2=80=99s exactly what happens an `async` block = is essentially always present as soon as `index.php` starts running.
It is necessary to determine whether this syntax truly provides enough ben= efits compared to the direct implementation.

I will think about it.= =C2=A0=C2=A0
--000000000000a146ca0630a4b3f2--