1 <?php declare(strict_types=1);
30 public function stretch(callable $callback)
32 $start_time = microtime(
true);
35 register_shutdown_function(
static function () use (&$halted) {
37 throw new \LogicException(
"Callback could not be stretched because it halted the programm.");
41 $return = $callback();
44 $elapsed_time_in_us = ((microtime(
true) - $start_time) * self::S_TO_US);
45 $duration_in_us = ($this->duration_in_ms * self::MS_TO_US);
47 if ($elapsed_time_in_us > $duration_in_us) {
48 throw new \RuntimeException(
"Execution of callback exceeded the given duration and could not be stretched.");
51 if ($elapsed_time_in_us < $duration_in_us) {
52 usleep((
int) round($duration_in_us - $elapsed_time_in_us));
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
stretch(callable $callback)