The event loop
Examples
Every example of this topic, with its output.
phasync::service#
phasync::run(function () {
phasync::service(function () {
phasync::sleep(10); // cancelled when the run has nothing else to do
});
phasync::sleep(0.1);
echo "main ends\n";
});
// run() returns after 0.1 secondsphasync::isRunning#
var_dump(phasync::isRunning()); // false
phasync::run(fn () => var_dump(phasync::isRunning())); // truephasync::getFiber#
phasync::run(function () {
$fiber = phasync::getFiber();
var_dump($fiber->isRunning()); // true
});DeadlockException#
try {
phasync::run(function () {
$done = new phasync\Util\WaitGroup();
$done->add();
$done->await(); // nobody calls done()
});
} catch (phasync\DeadlockException $e) {
echo $e->getMessage(), "\n";
}