This lightweight library provides a wait functionality for ReactPHP/promise library.
composer require adimihaila/promise-wait
<?php
use React\Promise\Deferred;
function doAsyncSomething() {
$deferred = new Deferred();
$deferred->resolve($value);
return $deferred->promise();
}
$value = doAsyncSomething()
->then(function ($response) {
sleep(5);
return $response++;
});
echo \AdiMihaila\Promise\wait($value);