◆ stretch()
ILIAS\HTTP\Duration\CallbackDuration::stretch |
( |
callable |
$callback | ) |
|
- Returns
- mixed|null
Definition at line 31 of file CallbackDuration.php.
33 $start_time = microtime(
true);
36 register_shutdown_function(
static function () use (&$halted):
void {
38 throw new \LogicException(
"Callback could not be stretched because it halted the programm.");
42 $return = $callback();
45 $elapsed_time_in_us = ((microtime(
true) - $start_time) * self::S_TO_US);
46 $duration_in_us = ($this->duration_in_ms * self::MS_TO_US);
48 if ($elapsed_time_in_us > $duration_in_us) {
49 throw new \RuntimeException(
"Execution of callback exceeded the given duration and could not be stretched.");
52 if ($elapsed_time_in_us < $duration_in_us) {
53 usleep((
int) round($duration_in_us - $elapsed_time_in_us));
The documentation for this class was generated from the following file: