Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126916 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 35FC21A00BC for ; Sun, 23 Mar 2025 16:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742749034; bh=r9MucoVx+ZRnD6ALdKNsZ5sSU3BJNS1MUPOkr3pYy6U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lKKETn961du3YVcwzTkSA+rFWklJ74/0nAymOU6YALAMANchnhxRYwFVc/G4CV1vX xsMDttS45mCZD0KJT8IeglE9rErFsFhcbX8B+Urfr+ZCP4QxcJO6QYQ7i4tHokAYpg vl0e46JY6UMFetZasWr27ioyX/IuZ4GNdLb66Ag//+RtMi4Ep8xmFPQUI+vuhR5Ubo HET1ebBmhVZzPSOjXZditVU04Gy6NJikw+MTtFGLWlBZkU9LEOZ2ReewGC6Eqv6OaU KFZpJ3esjmmhY2r/wKdi1qbdGc0jm6YBEsUQpYt5gnPM1vE3qkVU+PlKL7QMFTcVGz QOk6edL4VR/cg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1687A180072 for ; Sun, 23 Mar 2025 16:57:13 +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-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 ; Sun, 23 Mar 2025 16:57:12 +0000 (UTC) Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e6405e4ab4dso3911552276.0 for ; Sun, 23 Mar 2025 09:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742749182; x=1743353982; 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=rkZkqBxd4k6QjZOSIZEy49G+1qvsNJoCjiLKmen3iNg=; b=klUzQCvT3I9Pu/V419gaJ4vx+YHylk3m7afFHBggTSCVR1IgSIvPvnf7IS3nlSni/s ccbu9MCSMifez928A9yIxrI3xv0bwdm4n89euTL1PPRCCB5T+GT5zB9coNnFSx0u559n emUrHxxPPxF7yqbDPqIjELaRvO4HMRSf1zRL9MsT5G16UBy4HkG4UuwPAop+93C5Z8KC 45KMnbosfwoK94L344ODcKPBKUQwzGqTpkLTroduafRamSJqtY7Yore3T5VXFgsvroWr pxcGHkTrn0j5hOnBMPG3MLkfNiS55ajEWwpmnEbFyQvgSKMGZXOPeJewA0yqrIMkp6FH 71Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742749182; x=1743353982; 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=rkZkqBxd4k6QjZOSIZEy49G+1qvsNJoCjiLKmen3iNg=; b=dKKhDNMm1l0AkdXeIyg6cM6BfokCwZWPiy45mV2oPWJ5ylC4RuhNzeLoAJqxSfuCX6 ePNTUUJg+JB+IErNMxwlFuf/NcqWOGEiSRYvq0tFTS0mp2GEtfZ7xwPP1TEaIAyVt5xc 2UcQEvohvJEzJORYXrFy274BDDC3GjIxS2TDcPSwYakKcDzpetoUdtGLDERWvsRz/xT/ 1U4fj/hludrlYvwexigTXghkH1u8t0s8YtbBuicQrkv6JDa1KC0zTHBb9WfCz/dWKNaO VmGDN7nDZsinxtBz02Wq5bI10WfwDSMISXTf0drs75JoZoSyTZuGnGNADSUm7Dry+C4f x9vg== X-Gm-Message-State: AOJu0YycLALCzO+LwwOt+ULeVqZp6QQ6IoSBD+SAikTVsqB8TiwVR6RY PoKRtWMvPcXLI7+DmdIZWPE9AcsmFyJAjvPRbGQ2fBLLI54EBejkoq1sk+l/K/aeRZKWIOS0GXF NCtHUqrC8BxvUURguA0v4ZReIIUu0RyBi X-Gm-Gg: ASbGncu90gYwpFSniEdLKy9QfBxeyZsbVdm3kPPsSfBOXuijrd5ieuehJtzduFGicXQ ynHq5LeCnwN9V72N8DehzbeiXvrqlTM/bzapi1alpwJ0nPmkresLj68P+YJt1gohpi/SAhp1bki llcjTtxWZj7bpQCuq1+cYdezXuWA== X-Google-Smtp-Source: AGHT+IHWLaMvMmgQ+HwshD+gu93UnxADY2x5EJMqTlEcQpREN+JJ34UhZ5In+amIhfjJyHsgYvY6jQ5vd64uKxCIvhY= X-Received: by 2002:a05:6902:2503:b0:e5b:12f7:cda2 with SMTP id 3f1490d57ef6-e66a321d6d5mr13564003276.13.1742749181778; Sun, 23 Mar 2025 09:59:41 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <14fab616-e660-403c-a932-8225cf629a6e@app.fastmail.com> In-Reply-To: <14fab616-e660-403c-a932-8225cf629a6e@app.fastmail.com> Date: Sun, 23 Mar 2025 18:59:30 +0200 X-Gm-Features: AQ5f1Jov9mb05GZXlzcDzM-BWxAUFTu153m2zbs7_hksut3FfsWQx_6XMb3TsTs Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000e9a3b406310569ac" From: edmond.ht@gmail.com (Edmond Dantes) --000000000000e9a3b406310569ac Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello. > > So as an outline, I would recommend: > Yes, your suggestion is interesting. I'll think about that section next week. However, I can say that I=E2=80=99ve already dropped the =E2=80=9Cphilosoph= y=E2=80=9D section. I decided to move it into a separate article that will be available as an artifact. Such articles can be useful, but they overload the RFC. And the RFC is already large and complex, even considering that many things have been cut from it. > > The vast majority of the examples are "print Hello World" > I=E2=80=99ll add more realistic examples. But I won=E2=80=99t completely dr= op the echo examples where they=E2=80=99re the most useful. > > It's all a series > of functions that call each other to end up on a DB factory that uses a static variable, > so nothing there is injectable or testable. > Do you mean this code? ```php function getGlobalConnectionPool(): ConnectionPool { static $pool =3D null; if ($pool =3D=3D=3D null) { $pool =3D new ConnectionPool(); } return $pool; } ``` > so nothing there is injectable or testable. 1. Why must the code use DI? The use of a tool should be driven by the requirements of the task. Where do you see such requirements in the example code? There are no rules that dictate always using one pattern or another. Such rules are an anti-pattern themselves. 2. PHP has allowed testing code with factory functions using static variables for many years. > > It has the same "should be avoided in real-world development" problem, which means it doesn't tell me anything useful > If you remove the getGlobalConnectionPool function from the example, the meaning won=E2=80=99t change by even one percent. If a developer reading th= is example doesn=E2=80=99t understand that ConnectionPool is a dependency and = how the example works in real life, then that=E2=80=99s clearly not a problem with = the example. > > Consider: Suppose this RFC passed, but the follow-up to add a Scheduler did not pass, for > whatever reason. What does that leave us with? I think it means we have an approved RFC > that cannot be implemented. That's not-good. > Scheduler and Reactor are the implementation of this RFC. I don=E2=80=99t k= now whether they will be discussed in a separate RFC =E2=80=94 perhaps a PR wil= l be enough, but=E2=80=A6 To avoid ambiguity in the wording, I can mention that such components exist, without stating that they will be accepted separately. As I understand it, this resolves all concerns. > > That was not at all evident to me from reading it. > I=E2=80=99ll give this extra attention. > > Let me ask this: With the spawn/start/whatever keyword, what is the expected return value? > Does it block until that's done? Do I get back a future? > The spawn expression (I think this keyword will remain) returns a coroutine object. This object implements the Awaitable interface. Awaitable is not a Future, but it=E2=80=99s a base interface for objects that can be awaited. Since spawn returns a value that can be awaited, it can be used with await. await spawn means: wait until that coroutine finishes. await also returns a value =E2=80=94 the result of the coroutine=E2=80=99s = execution. > If the mental model is "take a function call like you already had The mental model that has settled in my mind over the past 3=E2=80=934 week= s looks like this: 1. Create a new execution context 2. Take this callable and its parameters and run them in the new context 3. Do it when possible (though I don=E2=80=99t know exactly when), but not = right now As far as I understand the meaning of the word spawn, it should match this model. --000000000000e9a3b406310569ac Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello.=C2=A0

>
>=C2=A0So as an outline, I would rec= ommend:
>

Yes, your suggestion is int= eresting. I'll think about that section next week.
However, I can say that I=E2=80=99ve already dropped the =E2=80=9Cphilosoph= y=E2=80=9D section. I decided to move it into a separate article that will = be available as an artifact.
Such articles can be useful, but they overload the RFC. And the RFC is alre= ady large and complex, even considering that many things have been cut from= it.=C2=A0=C2=A0

>
>=C2=A0The vast majority of the examples ar= e "print Hello World"
>

I= =E2=80=99ll add more realistic examples. But I won=E2=80=99t completely dro= p the echo examples where they=E2=80=99re the most useful.=C2= =A0=C2=A0

>
>=C2=A0It's all a series
> of functions that call each= other to end up on a DB factory that uses a static variable,
> so nothing there is injectable or= testable.
=
>

Do you mean this code?

```php
function getGlobalConnectionPool(): ConnectionPool
{
=C2=A0 = =C2=A0 static $pool =3D null;
=C2=A0 =C2=A0 if ($pool =3D=3D=3D null) {<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $pool =3D new ConnectionPool();
=C2=A0 = =C2=A0 }
=C2=A0 =C2=A0 return $pool;
}
```=C2=A0=C2=A0<= /div>

>=C2=A0 so nothing there is injectable or testa= ble.=C2=A0=C2=A0

1.=C2=A0 Why must the code use DI= ? The use of a tool should be driven by the requirements of the task. Where= do you see such requirements in the example code? There are no rules that = dictate always using one pattern or another. Such rules are an anti-pattern= themselves.
2.=C2=A0 PHP has allowed testing code with factory functions using static variables = for many years.=C2=A0

>
>=C2=A0 It has the same "should be avoided in real-world development" problem, which means it doesn't tell me an= ything useful
>

If you remove the getGlobalConnecti= onPool function from the example, the meaning won=E2=80=99t change b= y even one percent. If a developer reading this example doesn=E2=80=99t und= erstand that ConnectionPool is a dependency and how the exampl= e works in real life, then that=E2=80=99s clearly not a problem with the ex= ample.=C2=A0=C2=A0

>
>=C2=A0Consider: Suppos= e this RFC passed, but the follow-up to add a Scheduler did not pass, for>=C2= =A0whatever re= ason. What does that leave us with? I think it means we have an approved = RFC
> th= at cannot be implemented. That's not-good.
>

<= p class=3D"gmail-">Scheduler and Reactor are the implementation of this RFC= . I don=E2=80=99t know whether they will be discussed in a separate RFC =E2= =80=94 perhaps a PR will be enough, but=E2=80=A6

To avoid ambiguity in the wording, I can mention that s= uch components exist, without stating that they will be accepted separately= . As I understand it, this resolves all concerns.


<= div>>
>=C2=A0That was not at all evident to me from reading it.
>=C2=A0=C2= =A0
=C2=A0 I=E2=80=99ll give this extra attention.

=
>
>=C2=A0Let me ask this: With the spawn/start/whatever keyword, what is the= expected return value?
> Does it block until that's done? Do I get back a fut= ure?=C2=A0=C2=A0The spawn expression (I think this keyword will remain) returns a coroutine obj= ect.
This object implements the Awaitable interface. Awaitabl= e is not a Future, but it=E2=80=99s a base interface fo= r objects that can be awaited.

Since spawn returns a value that can be aw= aited, it can be used with await.
await spawn means: wait until that coroutine finishes.

=
await also returns a value =E2=80=94 the result of the co= routine=E2=80=99s execution.=C2=A0=C2=A0

>=C2= =A0If the mental mode= l is "take a function call like you already had

The mental model that has settled in my mind over the past = 3=E2=80=934 weeks looks like this:

  1. Create a new execution context

  2. Take this callable and its parameters and run them in t= he new context

  3. Do it when possible (though I don=E2=80=99t know exactl= y when), but not right now

As far as I understand the meaning of the word sp= awn, it should match this model.

--000000000000e9a3b406310569ac--