On 24/11/2025 16:57, Edmond Dantes wrote:
An error will occur for whom? SDK Susie when unit testing her library?
If SDK Susie used a new coroutine in which she calls the
`LoggerInterface::flush()` method, then with some probability the user
may notice that log entries are sometimes duplicated because the
`LoggerInterface::logs` property is not being cleared.
You could say that SDK Susie is responsible for this, because she ran
code that was never intended to be executed in a concurrent
environment.


Just to be clear, LoggerInterface is not an imaginary example, it's right here: https://www.php-fig.org/psr/psr-3/#3-psrlogloggerinterface

Packagist lists 9539 packages which depend on it, and has logged more than 1 billion installs: https://packagist.org/packages/psr/log

It is an absolute certainty that a PHP library will want to both use async I/O and accept a LoggerInterface as a dependency.


If it is an error for SDK Susie, what is her solution to allow users to pass in 
a logger to her library?
To avoid the error, SDK Susie must be sure that the
**LoggerInterface** implementation supports concurrent execution.


Susie doesn't know anything about the implementation, other than what is defined in the interface. That is literally the purpose of accepting an interface.

So it sounds like her only safe option is to restrict her usage of async coroutines to small self-contained pieces of code, and only use injected dependencies and callbacks in the "main" coroutine where they were passed in.


Regards,

--
Rowan Tommins
[IMSoP]

Reply via email to