Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128898 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 lists.php.net (Postfix) with ESMTPS id 4141E1A00BC for ; Wed, 22 Oct 2025 09:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761125737; bh=QaqQdJOBL6+J8sYlFolddslHsUKetudch3Qaf1A1dCU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oE10TyhIiAWEiMDRXcGCVIA30FNFnPmfKNezVYmawd3q2TnDlMRq41DZu7z2PvqOR zEGEQJBw58wZl2mDQX2vQbpH9eM0Akr1TmGYVdvFmjD9eaz08R3c34BBi9t1QlGoF/ onRrt08TK0Q1stjTUuTj+goQiRU/A+ntBU1wNQZvm+3wIZoGAKm7EFx77pPWZIe1h+ y7og7bKCaL41zMKKGpk6T8FvjOdID6pldf4kAxlgb07uE2KNyirmg2png0hlgjDq1H M8Qiir+r9oncVbCv+E3d/C6UXeiW2cLRTZ2Y2qYwHFPzt7vY5X/mdBVrhbAA3/yX8D uPPsWRzqtk8Gw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1E0FA1801D5 for ; Wed, 22 Oct 2025 09:35:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ua1-f43.google.com (mail-ua1-f43.google.com [209.85.222.43]) (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 ; Wed, 22 Oct 2025 09:35:33 +0000 (UTC) Received: by mail-ua1-f43.google.com with SMTP id a1e0cc1a2514c-932c4832197so1356446241.3 for ; Wed, 22 Oct 2025 02:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761125728; x=1761730528; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JaaP9QW2Ye15FjglrhaamsPl1e70+1B2WjVOXXVTyFQ=; b=I1BWGL5psZgEjVOlnBkM3K3qQuXnJvZisx/7yXVyiwzChVVIvyMOPC1OoVEmeJKGyE nPsCnalh5NtvXHFr/yESezkYqkrHKNiB2jOmA82pK8DCB+QQFdU1QMuRa6rgd7qjotAf v0VeFK/nTXn1EUFPCV8x4xlsGtrgSMtONxSqas4Oq0ri651fwpZaGqu2i79PhJ8890Fy bMs/hE5hyYuCn0VDpL6avqL+SMogJo2SY0bIkVV5bqMdLaTnd2tmIe1kqNls55O5IeRb eLq49RdFMnbh41gNdiVw7bZS8AayZoXNGghi/HRiIOkBcNWOt3N+2PNY9xz9IM/cdwp8 njGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761125728; x=1761730528; h=content-transfer-encoding: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=JaaP9QW2Ye15FjglrhaamsPl1e70+1B2WjVOXXVTyFQ=; b=TepnEUFmiG+u/oOX2Mqd7+mvJR+Nd2VOpDJ/JVtexfYJmMstN2EgFK9/NFSSeE8TMh MRneIgYyrzbo5BvouCDyMUCA3LJc2BTJcMQkWuI2QxLmQBb5248JDH/VYoCusMzqjSlT zJpI+RS0zLyPMHkqFrx8LzXUeuXhHR6B27mtYn3AqRym9wwNNcggwGKlKJnih6xJPmze EMpcxX+taWRiai5NXrOu91qhSethbAVFomEbqhIDKFoCk9S146rT7wILNvpiybRky7ck a/+wMxZlAAUTS9yf1NbzFhDjxOyeV00WFeUyR4JUnJgWDTH78P9su0V7U1Om+jJQDpgS Q1gg== X-Forwarded-Encrypted: i=1; AJvYcCWf+Re1Vn8e4jJsVKWqJFKikD0Ybs2wC6ZcVKFkkt1sFsDB4S9KCYEr3x7lcvB/1iF/hMoLYzqVn3o=@lists.php.net X-Gm-Message-State: AOJu0YzKXFfsVS64Zc2gLKxmk0wHN+e5DhFG/EMrsOS3mH1zZprzk/xN 3DC9KQMai3rCIXq/0au0Fjq32QjoDLaPXfqZ4JJvgIRt9gibQ1oaRGO08I6Sz1iELxFdnP4hqYY vXn9faqjyFGTEw+Ber10GzUYobdQsiUEbCOGVNzY7Yg== X-Gm-Gg: ASbGncsJCt/W88xdJWyzkJU0VDYNUe7JLLBP3Pf0o9Cp/Hrw6nIJTcvhH/02uKYeeEN CSyHv72AheE1szmG5SFf6zk3XIS3xsTdBJg9Qeu1NKbGlOGHWDBhS8TRCyC0Gbt7kYByWQ8mS0O tYQXmwtWXSwNRZyb+068u7jDOU1GW50cVLU+30kA0Q1LCBrJzaJ998gyUGaxFRaw3drxJh7mjug MNlVNatOZ974RChnQmcwLSrXoIsmd2oQoQJJd7xlq+V8YLdMgv4dZKQuyIqMatAiNsbX4fbET6j cRCHiFzyLDKBiHFGHV+/n0GCdQ== X-Google-Smtp-Source: AGHT+IFy/Z1mKYcRtF8zBUpdRy+NxoK4RYGd9tC9pV0tOHITFwtGjKcELLF4AKfonnFSeU/AT4TULU7SR03iaBXIIFQ= X-Received: by 2002:a05:6102:c4d:b0:5db:2301:a9f3 with SMTP id ada2fe7eead31-5db2301ac0fmr231274137.1.1761125728014; Wed, 22 Oct 2025 02:35:28 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <0e4e39d6-9cc9-4970-92e0-2463143b4011@app.fastmail.com> <37180d8d-85b4-49a3-a672-334bf4329470@app.fastmail.com> <2f8524a7-dea2-4fbf-933a-c538d3706253@app.fastmail.com> <151800a7-1094-49bc-8e43-c593a74741af@app.fastmail.com> In-Reply-To: <151800a7-1094-49bc-8e43-c593a74741af@app.fastmail.com> Date: Wed, 22 Oct 2025 12:35:16 +0300 X-Gm-Features: AS18NWDaXJ5MhU68pg1wqA2JIigLFfixq4gTIMmzZ9OKQUeWGZS2wY-UxKOejFY Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 To: Rob Landers Cc: Aaron Piotrowski , PHP Internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) > The example I gave is probably a good one? If I'm writing framework-y cod= e, how do I decide to await once, or in a loop? In other words, > how do I detect whether an Awaitable is idempotent or will give a differe= nt result every time? If I'm wrong, I could end up in an infinite loop, or = missing results. > Further, how do I know whether the last value from an Awaitable is the la= st value? I think if you could illustrate that in the RFC or change the sem= antics, that'd be fine. If a function knows nothing about the object it=E2=80=99s awaiting, it=E2= =80=99s equally helpless not only in deciding whether to use while or not, but also in determining how to handle the result. As for the infinite loop issue, the situation depends on the termination conditions. For example: ```php $queue =3D new Queue(); // Rust future-based while(true) { $future =3D $queue->next(); if($future =3D=3D=3D null) { break; } await($future); } ``` or ```php $queue =3D new Queue(); // Awaitable style while($queue->isClosed() =3D=3D=3D false) { await($queue); } ``` In other words, a loop needs some method that limits its execution in any case and it=E2=80=99s hard to make a mistake with that. > Accidentally sent too early: but also, what if there are multiple awaiter= s for a non-idempotent Awaiter? How do we handle that? All of this completely depends on the implementation of the awaited object. The Awaitable contract does not define when the event will occur or whether it will be cached. it only guarantees that the object can be awaited. However, the exact moment when the object wakes the coroutine and what type of data it provides are all outside the scope of the awaiting contract. In Rust, it=E2=80=99s common practice to use methods that create a new Futu= re (or NULL) when a certain action needs to be awaited, like: ```rust while let Some(v) =3D rx.recv().await { println!("Got: {}", v); } ``` Multiple awaits usually appear as several different `Future` instances that can be created by the same awaitable object. However, the Rust approach doesn=E2=80=99t fundamentally change... If the internal logic of an Awaitable object loses an event before a Future is created, the behavior is effectively the same as if the Future never existed. The advantage of the Rust approach is that the programmer can clearly see that a Future is being created (rx.recv() should return Future new one or the same?). (Perhaps the code looks more compact) But they still have to read the documentation to understand how this Future completes, how it=E2=80=99s created, and what data it returns. Wheth= er the last message is cached or not, and so on. In summary, a programmer must understand what kind of object they=E2=80=99r= e actually working with. It=E2=80=99s unlikely that this can be avoided.