mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Create callbackTimeout()
This commit is contained in:
parent
7dcc177424
commit
3e91f50966
@ -1036,3 +1036,25 @@ function renderStatus($hostapd_led, $hostapd_status, $memused_led, $memused, $cp
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes a callback with a timeout
|
||||
*
|
||||
* @param callable $callback function to execute
|
||||
* @param int $interval timeout in milliseconds
|
||||
* @return mixed result of the callback
|
||||
* @throws \Exception if the execution exceeds the timeout or an error occurs
|
||||
*/
|
||||
function callbackTimeout(callable $callback, int $interval)
|
||||
{
|
||||
$startTime = microtime(true); // use high-resolution timer
|
||||
$result = $callback();
|
||||
$elapsed = (microtime(true) - $startTime) * 1000;
|
||||
|
||||
if ($elapsed > $interval) {
|
||||
throw new \Exception('Operation timed out');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user