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]

Reply via email to