mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 10:49:37 +02:00
Move from React 0.4.0 to 0.3.4 for PHP 5.3 compatibility reasons
This commit is contained in:
parent
d3f01a3bc7
commit
7f82bea13e
50 changed files with 608 additions and 1937 deletions
|
@ -2,22 +2,21 @@
|
|||
|
||||
namespace React\EventLoop\Timer;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use React\EventLoop\LoopInterface;
|
||||
|
||||
class Timer implements TimerInterface
|
||||
{
|
||||
const MIN_INTERVAL = 0.000001;
|
||||
|
||||
protected $loop;
|
||||
protected $interval;
|
||||
protected $callback;
|
||||
protected $periodic;
|
||||
protected $data;
|
||||
|
||||
public function __construct(LoopInterface $loop, $interval, callable $callback, $periodic = false, $data = null)
|
||||
public function __construct(LoopInterface $loop, $interval, $callback, $periodic = false, $data = null)
|
||||
{
|
||||
if ($interval < self::MIN_INTERVAL) {
|
||||
$interval = self::MIN_INTERVAL;
|
||||
if (false === is_callable($callback)) {
|
||||
throw new InvalidArgumentException('The callback argument must be a valid callable object');
|
||||
}
|
||||
|
||||
$this->loop = $loop;
|
||||
|
|
|
@ -4,9 +4,12 @@ namespace React\EventLoop\Timer;
|
|||
|
||||
use SplObjectStorage;
|
||||
use SplPriorityQueue;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class Timers
|
||||
{
|
||||
const MIN_RESOLUTION = 0.001;
|
||||
|
||||
private $time;
|
||||
private $timers;
|
||||
private $scheduler;
|
||||
|
@ -30,6 +33,11 @@ class Timers
|
|||
public function add(TimerInterface $timer)
|
||||
{
|
||||
$interval = $timer->getInterval();
|
||||
|
||||
if ($interval < self::MIN_RESOLUTION) {
|
||||
throw new InvalidArgumentException('Timer events do not support sub-millisecond timeouts.');
|
||||
}
|
||||
|
||||
$scheduledAt = $interval + $this->getTime();
|
||||
|
||||
$this->timers->attach($timer, $scheduledAt);
|
||||
|
@ -48,17 +56,13 @@ class Timers
|
|||
|
||||
public function getFirst()
|
||||
{
|
||||
while ($this->scheduler->count()) {
|
||||
$timer = $this->scheduler->top();
|
||||
|
||||
if ($this->timers->contains($timer)) {
|
||||
return $this->timers[$timer];
|
||||
}
|
||||
|
||||
$this->scheduler->extract();
|
||||
if ($this->scheduler->isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
$scheduledAt = $this->timers[$this->scheduler->top()];
|
||||
|
||||
return $scheduledAt;
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue