Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127145 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 1ED141A00BC for ; Fri, 18 Apr 2025 00:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1744937735; bh=0MC7XayNBJfVUw+r4xrmc1zrqNDwWh5nP+KwAWrIBCM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=brPZ9x2bsLqZQ3SKkFRII+CKDLjEs03c5fLdkTidBkjtDJ+6Kx4G/UEq75sgWkyhO Wp+PwiGtp/cJhc9b0xXfPh8L+3mVmeHoIERknetRIuZsoECMCpmBvlc32jXkpH+7Ke wb0ec3DCYcdGKCK4v+efeW3TemOr3eqgR8ADp7tj7wjYnAZO6Djr4NMDWRSfaDXaKV BC7uoB9CkmMiEcIdfjlpd3AtaISf/5mt/NG5Ho9uLp3hACsTA5M6AUvkPa5zgUzOj1 rexzwugb7rXLDEGvfa2RF/+O5I3VG/aV4s9njDYfCuXsVumVrFN9BV7JO/vuFnqMJf xKi5nm14d9aLQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 41D78180055 for ; Fri, 18 Apr 2025 00:55:34 +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=0.6 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-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (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, 18 Apr 2025 00:55:31 +0000 (UTC) Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e728740b637so145397276.0 for ; Thu, 17 Apr 2025 17:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744937871; x=1745542671; 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=EiLZNjraPwnokJ1U5rx24WTMAgQREQ411zUObF1Av4U=; b=hxZDYUF2qzlNilCgO1ehjgxuM3ZgRQeesOjc0njwSl1+2uuLHyPdkCe8QzbnYyEOXP 62E24lfDana6LzAF7iOMNjZsgZM84NgVYmYdkFohNzgc7ZBqRaz2BIevrXynVRF0UXhP t7RvjAPz4yHoWT5E7OORMAJatmbLHem+1k90cqw2K6mdDPPbRTn2B6OOEeRBGF1eF0ni p40KD/5bu7iMWdOMhx8QvD4+zmJqKKDAK5ymTvx3neRQGIf5veg1XR/zKwU746/hX+j8 atbaelDARG03GO9+PT00kubGnKb4BWocgbPqhCi9wu2cHVeEdBMBnP4CgXD1fJfIYyfz D5cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744937871; x=1745542671; 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=EiLZNjraPwnokJ1U5rx24WTMAgQREQ411zUObF1Av4U=; b=fAf92u84GApHFWhYnSMrPargGz6juZ4aJSsu5elTccZhVZ4Z2rPRx0oI8/VnE5ySCF 9SnXEQvIcm2IOKWnkTz4Sbp+cWfLoKrufisBRLZ4txdpORAU2dR749nqoedNiftNA7Nl zqw+z6l3CW2mmMzhuv5/tPIyxmZR+tgS4ecg2l2VukrsOIuUZNslF/REKRCvOpcnlV6T fG37UG3R6Z5rqe7Pv90gTS0Q2zkyd+j6emQGGDm0McBC9FbWPkZLsp9+YUvz/9XYqcFK 40uB/3SiGpgZDUDXs4vity7mPLdLnefiXNyihwYKj0O8hfxZQi/R2hslOl29cIbRYJGG tLFw== X-Gm-Message-State: AOJu0YwDP7WKJ5rlx4ZzRirANJb94zuKAuuLQ5CwyJORLqmu/X1UEzHu 43cH6c0g3teEvNtV1dYkuDxGzsTsUg3TjkHec2DHJM0dHluX3kV+0W9mfftb6ClaO/EGP5ZEpz/ NcAKEbKyfSfX9zaJaCawK+BPTkSr2/HmqTLA= X-Gm-Gg: ASbGncsTZTj48rb4WK5IiPsEfI8kJ2oyydIzcVS/ZSOtSmc5oq2cK+CaV13AiKW8RKM qYyZWwEi1pmoRDpToEBmOB5SEVNpa321H1Y+SoT3hISilxDjmKfYDj5tvDSF3EHgHZ+LUOb6bj5 uv/Xjiallryly4Qm2S/p8BM1yEfzxP1pUyV5cn2PzY/0lEUWi96BjwHA== X-Google-Smtp-Source: AGHT+IG9k+zuTKOnF78jpmpPEmDMYb+2s8z/EdSJqX9fxLbd9PkaxQBpMDVWnns7GNkHpI6mLS0/xkpmPlfrG60TuCE= X-Received: by 2002:a05:690c:f05:b0:6fe:c2e6:bc66 with SMTP id 00721157ae682-706cccbb929mr5877827b3.2.1744937871150; Thu, 17 Apr 2025 17:57:51 -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: Thu, 17 Apr 2025 21:57:15 -0300 X-Gm-Features: ATxdqUFTW8R0GC4_NW-w_JiGonebulm-AtN8Z_BEH0p2jUR1krci8sJ7ukGvcLs Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC Stage 3 To: Edmond Dantes Cc: php internals Content-Type: multipart/alternative; boundary="000000000000f71d46063303011a" From: deleugyn@gmail.com (Deleu) --000000000000f71d46063303011a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Edmond! On Wed, Apr 16, 2025 at 7:02=E2=80=AFAM Edmond Dantes = wrote: > Good day, everyone. I hope you're doing well. > > I=E2=80=99d like to introduce the RFC for the True Async component. > > https://wiki.php.net/rfc/true_async > > This time the work took longer because I was exploring different > architectural options and paid more attention to how it works in other > languages. > > I was trying to find a balance between developer freedom and code safety, > and I believe I managed to find it. > > This RFC will go to a vote in about two weeks. > > Wishing you all a great day, and thank you for your feedback! > > -- > > Ed. > Thank you so much for such a comprehensive RFC in such a complex domain! The amount of care and work that went into this is quite visible. I want to preface that I have no voting rights, so take my feedback with a grain of salt. https://wiki.php.net/rfc/true_async#scope What happens if the coroutine didn't finish execution? does `disposeSafely()` means that it will wait until completion to safely clear it up or does it mean it will attempt to dispose and throw an exception if it fails to do so? ------------------------ https://wiki.php.net/rfc/true_async#taskgroup My first impression here was a little odd. Wouldn't it make more sense to hide the syntax behind the TaskGroup class? $taskGroup =3D new Async\TaskGroup(captureResults: true); $taskGroup->spawn(task1(...)); $taskGroup->spawn(task2(...)); [$result1, $result2] =3D $taskGroup->await() ------------------------ https://wiki.php.net/rfc/true_async#cooperative_cancellation Is there a time-limit imposed on the catch block? ------------------------ https://wiki.php.net/rfc/true_async#context Could this example be moved to a later block *after `*spawn use ()` has been introduced? Would it be possible to elaborate further an example that could not be easily replaced by `spawn use()`? In other words, what is unique about Context that makes it indispensable as opposed to `spawn use()`? ------------------------ https://wiki.php.net/rfc/true_async#combinators I may be misunderstanding, but it *feels* like `any()` is another way of `$taskGroup->race()`? and `all()` is another way of `$taskGroup->await()`? Would it make sense to elaborate further their difference in this example? Do you think the first RFC perhaps could propose one or the other and keep one of them for future scope? ------------------------ https://wiki.php.net/rfc/true_async#waiting_for_coroutine_results isn't this just standard PHP with extra steps? I'm assuming `await` here blocks and `spawn` creates a coroutine. Wouldn't every use of `await spawn` be effectively the same as just using PHP as-is today in blocking mode? ------------------------ https://wiki.php.net/rfc/true_async#awaiting_a_result_with_cancellation What is the output of this statement? Assuming it takes longer than 2 seconds, do we get null back? an exception? Additionally, this brings another syntax change with the `until` keyword that initially _feels like_ it could be a future scope to make the RFC shorter and more digestive? If users need to limit the duration of a coroutine maybe they can either cancel it or safely dispose? ------------------------ https://wiki.php.net/rfc/true_async#working_with_a_group_of_concurrent_task= s This feels like it reinforces my previous point. function mergeFiles(string ...$files): string{ $taskGroup =3D new Async\TaskGroup(captureResults: true); foreach ($files as $file) { $taskGroup->spawn(fn () =3D> file_get_contents ($file)); } return array_merge ("\n", $taskGroup->await());} Note: I *think* you wanted to use `implode` instead of `array_merge` here. ------------------------ https://wiki.php.net/rfc/true_async#await_all_child_tasks I want to make a side comment that this example reinforces my initial sentiment that `until` syntax is not required on the first version? However, it's relevant to mention I didn't fully understand this example. It feels to me that the inner function `processJob` is supposed to await only its own set of coroutines while the `processBackgroundJobs` is awaiting on all hierarchy as the comments says. However, if the scope is being inherited, wouldn't that make the inner `processJob` await basically be awaiting the entire scope? Effectively the inner await and the outer await mean the same thing? ------------------------ https://wiki.php.net/rfc/true_async#binding_coroutines_to_a_php_object I'm not trying to be pedantic, but it is a rather complex RFC. This seems to be the first time it uses `stop` a coroutine. Is it different from `cancel()` and `disposeSafely()`? How so? ------------------------ https://wiki.php.net/rfc/true_async#namespace This seems like a void statement. Whether the namespace gets used in a way that respects this statement or not, it doesn't mean that PHP won't break BC in future versions when the language itself defines a symbol that has been defined in userland. ------------------------ https://wiki.php.net/rfc/true_async#hipriority_strategy Seems like a good candidate for future scope and/or left for userland since the SpawnStrategy interface already exposes the necessary capabilities? ------------------------ https://wiki.php.net/rfc/true_async#suspension This explains a bit more the "Cooperative cancellation" example early in the RFC, but it does seem rather awkward to suspend the main in order to start a coroutine. Shouldn't await be used for that instead? Would making `suspend` a fatal error inside the main flow somehow worse for implementation? ------------------------ Sorry for not reading the entire RFC before replying. I hope to get through it all in the following days. Thanks! --=20 Marco Deleu --000000000000f71d46063303011a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi=C2=A0Edmond!
On Wed, A= pr 16, 2025 at 7:02=E2=80=AFAM Edmond Dantes <edmond.ht@gmail.com> wrote:
=

Good = day, everyone. I hope you're doing well.

I=E2=80=99d like to intr= oduce the=C2=A0RFC=C2=A0for the True=C2=A0Async= =C2=A0component.

https://wiki.php.net/rfc/true_async

This time the work took longer because I was explor= ing different architectural options and paid more attention to how it works= in other languages.

I was trying to find a balance between developer freedom and code sa= fety, and I believe I managed to find it.

=C2=A0 This RFC will go to = a vote in about two weeks.=C2=A0=C2=A0

Wishing you all a great day, a= nd thank you for your feedback!

--

Ed.

Thank you so much for such a comprehensive RFC in s= uch a complex domain! The amount of care and work that went into this is qu= ite visible. I want to preface that I have no voting rights, so take my fee= dback with a grain=C2=A0of salt.


What happens if the coro= utine didn't finish execution? does `disposeSafely()` means that it wil= l wait until completion to safely clear it up or does it mean it will attem= pt to dispose and throw an exception if it fails to do so?

------------------------


My first impres= sion here was a little odd. Wouldn't it make more sense to hide the syn= tax behind the TaskGroup class?

$taskGroup =3D new Async\TaskGroup(captureResults: true);

$taskGroup->spawn(task1(...));

$taskGroup->spawn(task2(...));

[=
$result1, $result2] =3D $ta=
skGroup->await()
------------------------


Is there a time-limit imposed on the catch bl= ock?

------------------------

=

Could this examp= le be moved to a later block after `spawn use ()` has been introduce= d? Would it be possible to elaborate further an example that could not be e= asily replaced by `spawn use()`? In other words, what is unique about Conte= xt that makes it indispensable as opposed to `spawn use()`?

<= /div>
------------------------


I may be misunderstanding, b= ut it feels=C2=A0like `any()` is another way of `$taskGroup->race= ()`? and `all()` is another way of `$taskGroup->await()`? Would it make = sense to elaborate further=C2=A0their difference in this example? Do you th= ink the first RFC perhaps could propose one or the other and keep one of th= em for future scope?

------------------------


isn't this just standard PH= P with extra steps? I'm assuming `await` here blocks and `spawn` create= s a coroutine. Wouldn't every use of `await spawn` be effectively the s= ame as just using PHP as-is today in blocking mode?

------------------------

What is the output of this statement? Assuming it takes longer = than 2 seconds, do we get null back? an exception?

Additionally, this brings another syntax change with the `until` keyword t= hat initially _feels like_ it could be a future scope to make the RFC short= er and more digestive? If users need to limit the duration of a coroutine m= aybe they can either cancel it or safely dispose?=C2=A0

------------------------


This feels like it reinforces my previous point.<= /div>

function mergeFiles(string ...$files<=
span class=3D"gmail-br0" style=3D"color:rgb(62,153,159);font-weight:600">)<=
/span>: st=
ring
{=

    $taskGroup =3D <=
span class=3D"gmail-kw2" style=3D"color:rgb(66,113,174);font-weight:600;fon=
t-style:italic">new Async\TaskGroup(captureResults: true);
=C2=A0
    foreach ($files as $file) {
       $taskGroup=
->spawn(fn () =3D> file_get_contents($file));
    }
=C2=A0
    return array_merg=
e("\n", $taskGroup->await());
}=
Note: I think=C2=A0you wanted to use `implod= e` instead of `array_merge` here.

----------------= --------


I want to make a side comment that= this example reinforces my initial sentiment that `until` syntax is not re= quired on the first version?
However, it's relevant to mentio= n I didn't fully understand this example. It feels to me that the inner= function `processJob` is supposed to await
only its own set of c= oroutines while the `processBackgroundJobs` is awaiting on all hierarchy as= the comments says. However, if the scope is being
inherited, wou= ldn't that make the inner `processJob` await basically be awaiting the = entire scope? Effectively the inner await and the outer await mean
the same thing?

------------------------


I'm not trying to be= pedantic, but it is a rather complex RFC. This seems to be the first time = it uses `stop` a coroutine. Is it different from=C2=A0 `cancel()` and `disp= oseSafely()`? How so?

------------------------


=
This seems like a void statement. Whether the namespace gets used in a= way that respects this statement or not, it doesn't mean that PHP won&= #39;t break BC in future versions when the language itself defines a symbol= that has been defined in userland.=C2=A0

--------= ----------------


Seems like a good candidate fo= r future scope and/or left for userland since the SpawnStrategy interface a= lready exposes the necessary capabilities?

-------= -----------------



--000000000000f71d46063303011a--