Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126895 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 5904B1AD8E4 for ; Fri, 21 Mar 2025 11:50:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742557700; bh=9+cingv9Je167MeK+xPoQeig30jlojzY/R/ftimmlQM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Ndr4ey0gOTUpY21sr6wbEHYeJAoiMQWf+IzvPWbQTBa6GxvZdlIbIkdB3Wg9s8VpE //Vy0WxEHRs0VvZaN+Tp6WQ+5sQkK8+fgdeWy1f2xRB0CAN9510di3REohca9Ar+Dt v/0jFOMzwreayA/qw5Em8U5M1WDVP1Xxheih1lq8b9X6iYFr848RfMOAb5R7d2HbSt KG7p/fROSXoNQAwLNyo2Ldg49WitD8XrRwbTTqHSgl0scd2NcpO/rjGslvGrQLyQkF gv0YoiTUz3jAFUTl7eezm6b6X3cZg8DJqs4amjdrsFGq7fuuNa5RXkuRL7I+hVS6HC 5g8V5xR8+Y5gg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6A25A180708 for ; Fri, 21 Mar 2025 11:48:17 +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.0 required=5.0 tests=BAYES_20,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-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (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 ; Fri, 21 Mar 2025 11:48:15 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e6405e4ab4dso2588088276.0 for ; Fri, 21 Mar 2025 04:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742557845; x=1743162645; 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=Heq/NijbtUJpcPn/FwH5brkpg1qU+Q8lnVcxB8DLXtc=; b=i3JfkJ/qUAPpcmBGAzrbbEjTTAuYl0uO+wWJS7yGhS1+fWJDTHzZPsMBC9uDERhY2/ dekNBbpJkbIKVng5miKPYmpKdhWdhl0fgIjdKomjxC9qR2yGbWPGcngqBjavAHkVqNgw AVkNkdM0E0QiKjLRWrrZ6HYuLLEfXL0Ea141vUnFQyS44D4KZxpqfDXff7Rl3E1X1my0 e+XaIDvs9LHh3uQvEQoy0e7r/vgFU1dj78Cpm6BxlvtL5wM+IThLHYdQSNc7QlAhc6OC 9UYFQCSu+8qTIliy6lpWVnHkUlX31i+MJZYZw8wcNDciSjEGMEv5jt1umLYQes0kgVeV /CCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742557845; x=1743162645; 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=Heq/NijbtUJpcPn/FwH5brkpg1qU+Q8lnVcxB8DLXtc=; b=Z2i1CA3u3bKEIST4Y364loOctuA1YknvHmIz1lPnryH08rFYWGmGKeXxsYsDtfzxwH 8QB7ENX+4f5X0NKrMXsDN/gLhgyciYA+848w3dBI2KjclcrtO14YgTr+iJ4oo0lOAxYo fPTEPrgtqY2m5vlu8VDvnXhGWvOj5SPL7PReSIgJ88yapcHcCtTeQqPHvn86n5Zjioeo Oqkl0R/vOJRmI3hQkGXvOvnMN71o1R802hex7DWkFP31mtBost76qDyFqcSn5DuIRIT0 7ozR4rz8DksJEO0gpDWLnGtyIdjfHqoArwqADxoV75vtLrNWNl9UcWMn9A8rF/eJnmQ4 aQjQ== X-Gm-Message-State: AOJu0YwUdlvvrar5rqstRYzk2zowz3ilR5ZFDcqPP3BQbNLHN8i1y5u+ bNMeMeCEPwvB6sLTO/MhyvVJ1ayJ88RJF0WjtXLoRpyFKWuhAEFEctqxbH3Gtkn+jr4fScSpflt A+TPiUFZ7pJrNfQizzJRaEx/t1jWngj6BG7MHVw== X-Gm-Gg: ASbGncv9yCgFswOTmqFgmVrkw668rPh8S2jroX7fxZJkgDtstRmux491woMv5oDgwtb xgt3Ri9/RtuxtJUBhWoynkYTAc1IP0fDYxa5QOjD5ZAP1x5oQJpGtkr4/z2Oux/Zhb84VsBXd71 hqe+NDZ6SE8CmYRQnNBj2mst/Tow== X-Google-Smtp-Source: AGHT+IGrCGT/EfMHst5o6wN2Zw1+eES6z+gtg0V6JLbzsWHAOQqil3jnQjdInE0c9D7naSBF4xWNEkkLRGikZywA3dw= X-Received: by 2002:a05:6902:2007:b0:e5e:18bc:f17 with SMTP id 3f1490d57ef6-e66a31c61bemr3967683276.1.1742557845254; Fri, 21 Mar 2025 04:50:45 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <0A5443F7-6C29-474A-A286-42A76FF9CB33@gmail.com> In-Reply-To: <0A5443F7-6C29-474A-A286-42A76FF9CB33@gmail.com> Date: Fri, 21 Mar 2025 13:50:33 +0200 X-Gm-Features: AQ5f1Jq8EcpRc3U0WAf_Gy6stszulptgl3ElNMPu9Gos2lrQ3-OrUbvC8xhbEW4 Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: Daniil Gentili Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000005dff6d0630d8dd6d" From: edmond.ht@gmail.com (Edmond Dantes) --0000000000005dff6d0630d8dd6d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > You already explicitly await all fibers spawned in the generateReport function, you get all the data you need, any extra spawned fibers should not interest you for the purpose of the logic of generateReport. > In this specific code, it only awaits the tasks it has launched itself. So, if another function mistakenly starts a coroutine in the current `Scope`, that coroutine will be cancelled when the scope is destroyed. On the other hand, code that does `await $scope` assumes that the programmer *intends* to wait for everything and understands the implications. This usually means that the functions being called are part of the same module and are designed with this in mind. As for library functions =E2=80=94 **library functions MUST understand what= they are doing**. If a library function creates resources indiscriminately and doesn=E2=80=99= t clean them up, the language cannot be held responsible. If library functions don=E2=80=99t manage resource ownership properly, the = language cannot take responsibility for that either. > > This is because again, the main use case listed of making sure all fibers are done after a request is a footgun is a non-business-logic requirement, > an exercise in functional purity that also reduces caching and concurrency opportunities, as mentioned before. > In this RFC, there is no such primary use case. There is the `await $scope` construct, but it can no longer be used as the default. There used to be a `await currentScope()` construct, which was a footgun = =E2=80=94 but it will no longer exist. I also removed `globalScope`, because in 99% of cases it=E2=80=99s an anti-= pattern and can be easily replaced with code that creates a coroutine in a separate `Scope`. Through writing examples, this became clear. > > A (somewhat bikesheeding, but this has been the vast majority of the posts on this thread anyway) note is that await could also be made to accept an iterable of futures, avoiding the use of Async\all combinators. > I considered this option =E2=80=94 it looks nice with an array =E2=80=94 bu= t for some reason, it's not implemented in any language. And here's why. When you allow await to work with an array, it leads to significant complications. Because once you support arrays, you naturally want to add more variants, like: - await first - await any - await ignore and so on. And with additions like await until or await limit, it becomes a very large and complex statement. After exploring different options, I also came to the conclusion that using a function which returns a `Future` from parameters is more flexible and better than having a multitude of options. The only unresolved question is until, because it could be convenient. But it doesn=E2=80=99t exist in any other language. --0000000000005dff6d0630d8dd6d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>
>=C2=A0 You already explicitly await all fibers spawned in the generateReport funct= ion, you get all the data you need, any extra spawned fibers should not int= erest you for the purpose of the logic of generateReport.
>

In this specific code, it only awai= ts the tasks it has launched itself. =C2=A0
So, if another function mist= akenly starts a coroutine in the current `Scope`, that coroutine will be ca= ncelled when the scope is destroyed.

On the other hand, code that do= es `await $scope` assumes that the programmer *intends* to wait for everyth= ing and understands the implications. =C2=A0
This usually means that the= functions being called are part of the same module and are designed with t= his in mind.

As for library functions =E2=80=94 **library functions = MUST understand what they are doing**. =C2=A0
If a library function crea= tes resources indiscriminately and doesn=E2=80=99t clean them up, the langu= age cannot be held responsible. =C2=A0
If library functions don=E2=80=99= t manage resource ownership properly, the language cannot take responsibili= ty for that either.

&g= t;=C2=A0
>=C2=A0 This is because again, the main use case listed of making sure all fibers a= re done after a request is a footgun is a non-business-logic requirement, <= br>> an exercise in functional purity that also reduces caching and conc= urrency opportunities, as mentioned before.
>
<= br>
In this RFC, there is no such primary use case. = =C2=A0
There is the `await $scope` construct, but it can no longer be us= ed as the default. =C2=A0
There used to be a `await currentScope()` cons= truct, which was a footgun =E2=80=94 but it will no longer exist.

I = also removed `globalScope`, because in 99% of cases it=E2=80=99s an anti-pa= ttern and can be easily replaced with code that creates a coroutine in a se= parate `Scope`. =C2=A0
Through writing examples, this became clear.
<= br>>
>=C2=A0 A (somewhat bikesheeding, but this has been the vast majority of the posts = on this thread anyway) note is that await could also be made to accept an i= terable of futures, avoiding the use of Async\all combinators.
>

I considered this option =E2= =80=94 it looks nice with an array =E2=80=94 but for some reason, it's = not implemented in any language.

And here's why.

When you allow await to work with an array, it leads to sig= nificant complications.
Because once you support arrays, you naturally want to add more variants, l= ike:

  • await first
  • await any
  • await ignore
    and so on.

And with additions like await until or await limit, it becomes a very large and complex statement.

After exploring = different options, I also came to the conclusion that using a function whic= h returns a `Future` from parameters is more flexible and better than havin= g a multitude of options.

The only unresolved question is u= ntil, because it could be convenient.
But it doesn=E2=80=99t exist in any other language.=C2=A0=C2=A0

--0000000000005dff6d0630d8dd6d--