automapper
automapper copied to clipboard
Fix race condition in EvalLoader
When using swoole coroutines with eval loader, where is a possibility to get an error Cannot declare class {class}, because the name is already in use, because coroutines share memory and declared classes.
Can be tested like this
require 'vendor/autoload.php';
readonly class Dto
{
public function __construct(
public int $id,
) {}
}
$mapper = \AutoMapper\AutoMapper::create();
$data = ['id' => 1];
\Co\run(static function () use ($mapper, $data) {
for ($i=1; $i < 100_000; $i++) {
\Co\go(static fn () => $mapper->map($data, Dto::class));
}
});