mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 19:04:52 +00:00
Reintroduce Webklex IMAP for ticket processing as PHP-IMAP is no longer being developed. This is optional for now and considered beta can be found in cron/ticket_email_parser.php
This commit is contained in:
86
plugins/vendor/illuminate/support/Timebox.php
vendored
Normal file
86
plugins/vendor/illuminate/support/Timebox.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class Timebox
|
||||
{
|
||||
/**
|
||||
* Indicates if the timebox is allowed to return early.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $earlyReturn = false;
|
||||
|
||||
/**
|
||||
* Invoke the given callback within the specified timebox minimum.
|
||||
*
|
||||
* @template TCallReturnType
|
||||
*
|
||||
* @param (callable($this): TCallReturnType) $callback
|
||||
* @param int $microseconds
|
||||
* @return TCallReturnType
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function call(callable $callback, int $microseconds)
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
try {
|
||||
$result = $callback($this);
|
||||
} catch (Throwable $caught) {
|
||||
$exception = $caught;
|
||||
}
|
||||
|
||||
$remainder = intval($microseconds - ((microtime(true) - $start) * 1000000));
|
||||
|
||||
if (! $this->earlyReturn && $remainder > 0) {
|
||||
$this->usleep($remainder);
|
||||
}
|
||||
|
||||
if ($exception) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the timebox can return early.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function returnEarly()
|
||||
{
|
||||
$this->earlyReturn = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the timebox cannot return early.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function dontReturnEarly()
|
||||
{
|
||||
$this->earlyReturn = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleep for the specified number of microseconds.
|
||||
*
|
||||
* @param int $microseconds
|
||||
* @return void
|
||||
*/
|
||||
protected function usleep(int $microseconds)
|
||||
{
|
||||
Sleep::usleep($microseconds);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user