Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129007 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 DFA1E1A00BC for ; Thu, 30 Oct 2025 14:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761834858; bh=OtHfDNKX59thajj4wTn0wL7b3/p4qGodl2h3W5pc/eI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NBhvOCqSCl19q7PTWsJaKJ5occVC+OQUjQoF/tieFRZrkGuJ/xRSmetQ+CSUdQwUQ mWA4393Nf38RdHN7M4UdxspfE0lpY9N26HH3iI1aVTwRrvK/zRNx28xKBXQQl7V0Ai +RDuKA0MJqr0E5CH2XgtE9d/NQkL4w+t/pe5atQOwqADrSlvB/zRYI52AYzYJjzlqy HnFSp20MlP5bi3IHiuOg2K6VJP97aNZ7Eg8tS5hzLsM0yhEOoDUy5UYw4Sut1izcWq rU7Cze+g1QFkZ6yoYhFAMRaE1Pbz4WMV6U5MqzcOzuq1zLYdSRKySevwawfPubw6Mn Zv334S00I3Y0Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D7D9F18007E for ; Thu, 30 Oct 2025 14:34:17 +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,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) (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 ; Thu, 30 Oct 2025 14:34:17 +0000 (UTC) Received: by mail-vs1-f47.google.com with SMTP id ada2fe7eead31-5ce093debf6so1197458137.1 for ; Thu, 30 Oct 2025 07:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761834852; x=1762439652; 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=cw5Zb9VlXU5naYt8/MCPV7wc7hOIfcUvdUjris6h0bM=; b=FRMeR9pXAz7Aw6TSLwfdSOv70LE5JWp3oqkWYbNBQPi9Octw0ozJC0q5DLkUjsFb5r O24Rw72vvxw7sYET209/0g1ipKg5DYDciiL1r36hQf3CE7XuwvYyWVp9/14PnzfdBNlv PoD7BNDfcTh9BacrntX+JnIw/8sfhayzIi4FRGot9HMGOqOBRptJ0Uo1knh5f0m/Ak9i q/E55aOUe5bM/K0mmRZozUXRpoUKagr9cP6omEVSfPw0tFiN76PRYkKgHp5q+cTwX6ON 4Caat83Um45RCHW7pdef7rNauxvlKY96JpaHCQ2PD9EvM5FUEsVdkaI7Pt6rOMBx/sEs WzMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761834852; x=1762439652; 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=cw5Zb9VlXU5naYt8/MCPV7wc7hOIfcUvdUjris6h0bM=; b=Op4xyrRCsOiJIs3sVxifxdbS7k60Mnfv213IBFz4mYlUVbo4a8sISdSObp/TJ4RuNJ knPqQySgt/OgMFrXRVSsAVJGqkHmtHMAz20LohAjxIaWKI+uqFzenRGs6k8LvXi7SkG+ lm7UcIj9kRDY8d4M0olAOQOVKDGPX9eJBLzf/dVuzk7J8nrIlg4QaXnwNxkyCgZzGkPd wiriNRQLl45J6vShjkdA8zqOWDXwUrTGy2huThR/gMATqSryv+50H1/tW4klGkvYyEpY VNLv6s6eClQvS2F0iDiqyXpsOxo3XPKNqotJkhY6th4w9uQm5/9LubpX9MvejnHQyRH6 W22A== X-Gm-Message-State: AOJu0YzNMqgmWFI9G/zNEH8NXL+LUQbH+sLLClQFFtPYW38O6arhuxD/ M/OIKAmRgmjiNis6B6mNclL/5WIvtU+LJWlHS4nEdmVVNo1mv0CdtOWPmbLgCcbMW5RIKo+qpNb KbwOn5VZ/n1opwVY4PMsN8jTfBo5BdQE= X-Gm-Gg: ASbGncsv4mD19m1AhjlEVUqwtfKAo8qnw4EYPIfnQXOFVb+HuRGRK9rK7yUnlku004U ECff17kWqrSEYS48mmJicHjqmGD5vZSZppGMnRO/pzkRrgsJfe793N3vzA+12SWr1Kr4T7b3M69 JiKWT1HdvtImXtpy2soWi3zMfdUqrVHkVeua4uYfx3M6ajKDzBSuPBUIMSozNqFnKA1L81JhYX5 CRiW7FMXfGHsNVfH3d1OukG5ypYLZMW7Q50Uzd0nSKzF1ybtMFYzu1iRgAIPQMs20dog+Lk02E3 U+YhSROWKc0h1tZm X-Google-Smtp-Source: AGHT+IEhZAcRooD2zuc9g+/cvK/7PqEuYG2Gnp0wd+pe07KDg8BlJ2UU35OyjKPpPVs9ids+0N4MbxhfjAZ/qcGF/bc= X-Received: by 2002:a05:6102:390e:b0:5d3:fef5:8724 with SMTP id ada2fe7eead31-5db906918dcmr2467790137.26.1761834851728; Thu, 30 Oct 2025 07:34:11 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 30 Oct 2025 16:34:00 +0200 X-Gm-Features: AWmQ_bn3WmTKrGjZT-w2b1A1XwGemHtNHHWWxg-x637WYxW6sLCxOGCqcn1JElE Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC Stage 5 To: Deleu Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) Hi > One minor question: is this section https://wiki.php.net/rfc/true_async#a= waiting_a_result_with_cancellation named wrongly? I'm not sure how this sni= ppet of code relates to cancellation. Yes, second parameter is a CancellationToken. (spawn('sleep', 2)). > What's the difference between Multishot Awaitables and Generators? There=E2=80=99s nothing in common between them. It=E2=80=99s better to think of asynchronous objects as components of an EventDriven pattern. > doesn't this mean that multishot awaitables are not really capable of bei= ng awaited anymore? Exactly. It=E2=80=99s not needed for now. > Shouldn't FutureLike be Awaitable and what has been described as Multisho= t awaitables should actually be generators / array of / list of Awaitables? FutureLike is a child interface of Awaitables. > we can assume that if a function used to throw an Exception and a future = version stops throwing said exception it is not considered a BC Break. This RFC does not change the behavior of existing functions. For example, sleep works the same as before. PHP functions that previously did not throw a CancellationError do not throw it in this RFC either. However, when you use functions (await example) that do throw these exceptions, you handle them the same way as always. In that sense, there=E2=80=99s no new paradigm. > What if the first version of Async PHP provides userland with the ability= to trigger coroutines for reading purposes only? Sorry, but I couldn=E2=80=99t understand why this needs to be done. There=E2=80=99s nothing terrible about canceling write operations =E2=80=94= no =E2=80=9Cshooting yourself in the foot=E2=80=9D either. A program can termi= nate at any moment; that=E2=80=99s perfectly normal. The concept of Cancellation by Design isn=E2=80=99t about guns =E2=80=94 it= =E2=80=99s about reducing code. That=E2=80=99s all. In the Swift language, for example, a different concept is used: cancellation is always written explicitly in the code, like this: ```swift func fetchData() async throws -> String { for i in 1...5 { try Task.checkCancellation() print("Fetching chunk \(i)...") try await Task.sleep(nanoseconds: 500_000_000) } return "Data loaded" } ``` The only question is about how much code you write and the likelihood of errors. The more code you write, the higher the chance of making one. Write safety is a different topic; it concerns how code is implemented at the lowest level, meaning the code that calls OS functions. Cancelling a coroutine cannot interrupt a kernel-level write operation =E2=80=94 it can only interrupt waiting for the write, and what to do next = is decided by the user-level code. The cancellation design was implemented as early as 2015 in Python (and in other languages as well) and has worked perfectly since then. For languages like PHP, it=E2=80=99s a convenient and, most importantly, familiar mechanism. The real problem is that an exception can accidentally be caught without exiting the coroutine. For example: ```php catch (\Throwable $e) { Logger::log(); } continue; ```