Re: [VOTE] True Async RFC 1.6

From: Date: Mon, 24 Nov 2025 13:56:23 +0000
Subject: Re: [VOTE] True Async RFC 1.6
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-129432@lists.php.net to get a copy of this message
On 24/11/2025 12:15, Bart Vanhoutte wrote:
    Will Legacy Les see a side effect when he upgrades to SDK Susie's
    new async library?
For clarity, Susie's code has turned from something sync like:
function getFoo(): Foo
{
  $resultOne = sendHttpRequest('one');
  $resultTwo = sendHttpRequest('two');

  return new Foo($resultOne, $resultTwo);
}
into something async like:
function getFoo(): Foo
{
  $results = await Async\all([
    spawn sendHttpRequest('one'),
    spawn sendHttpRequest('two')
  ]);

  return new Foo($results[0], $results[1]);
}

Is that correct Rowan?
It could be as simple as that, but it might also have Coroutine / Future objects held internally rather than immediately awaited, e.g. she might have changed this:
function getNextResult(): Result
{
    if ( $this->needNextPage() ) {
        $this->currentPageOfResults = $this->fetchNextPage();
    }
    return array_shift($this->currentPageOfResults);
}
To this:
function getNextResult(): Result
{
    if ( $this->needNextPage() ) {
        $this->currentPageOfResults = await $this->nextPageFuture;
        $this->nextPageFuture = spawn $this->fetchNextPage();
    }
    return array_shift($this->currentPageOfResults);
}
There might also be interleaved code which is passed in from the application - i.e. code written by Beginner Bob or Legacy Les. For instance, an implementation of the PSR-3 LoggerInterface, which might be referenced inside the fetchNextPage() method which is being run asynchronously. [P.S. Reminder: place your reply _below_ an edited quote, not _above_.] -- Rowan Tommins [IMSoP]

Thread (106 messages)

« previous php.internals (#129432) next »