diff options
author | Mario <mario@mariovavti.com> | 2020-05-07 23:35:02 +0200 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-05-07 23:35:02 +0200 |
commit | fae70bf0a7f1b566d25e30064f60d58ab150951a (patch) | |
tree | 1714511edb85ed0e28034ed9371d5fc515504fd6 /vendor/sabre/event/lib/Loop | |
parent | ffd2faf8a09a870e8dbecb3ad168e0a9b25941d3 (diff) | |
download | volse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.tar.gz volse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.tar.bz2 volse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.zip |
Revert "composer updates"
This reverts commit dbfe748d274f6843fc91a3071df7be45c4ab5b00
Diffstat (limited to 'vendor/sabre/event/lib/Loop')
-rw-r--r-- | vendor/sabre/event/lib/Loop/Loop.php | 147 | ||||
-rw-r--r-- | vendor/sabre/event/lib/Loop/functions.php | 85 |
2 files changed, 146 insertions, 86 deletions
diff --git a/vendor/sabre/event/lib/Loop/Loop.php b/vendor/sabre/event/lib/Loop/Loop.php index ec09be921..301fe8920 100644 --- a/vendor/sabre/event/lib/Loop/Loop.php +++ b/vendor/sabre/event/lib/Loop/Loop.php @@ -1,6 +1,4 @@ -<?php - -declare(strict_types=1); +<?php declare (strict_types=1); namespace Sabre\Event\Loop; @@ -17,19 +15,20 @@ namespace Sabre\Event\Loop; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class Loop -{ +class Loop { + /** * Executes a function after x seconds. + * + * @return void */ - public function setTimeout(callable $cb, float $timeout) - { + function setTimeout(callable $cb, float $timeout) { + $triggerTime = microtime(true) + ($timeout); if (!$this->timers) { // Special case when the timers array was empty. $this->timers[] = [$triggerTime, $cb]; - return; } @@ -47,12 +46,14 @@ class Loop [[$triggerTime, $cb]] ); break; - } elseif (0 === $index) { + } elseif ($index === 0) { array_unshift($this->timers, [$triggerTime, $cb]); break; } - --$index; + $index--; + } + } /** @@ -61,12 +62,12 @@ class Loop * The value this function returns can be used to stop the interval with * clearInterval. */ - public function setInterval(callable $cb, float $timeout): array - { + function setInterval(callable $cb, float $timeout) : array { + $keepGoing = true; $f = null; - $f = function () use ($cb, &$f, $timeout, &$keepGoing) { + $f = function() use ($cb, &$f, $timeout, &$keepGoing) { if ($keepGoing) { $cb(); $this->setTimeout($f, $timeout); @@ -81,24 +82,32 @@ class Loop // Because I'm worried people will be confused by using a boolean as a // sort of identifier, I added an extra string. return ['I\'m an implementation detail', &$keepGoing]; + } /** * Stops a running interval. + * + * @return void */ - public function clearInterval(array $intervalId) - { + function clearInterval(array $intervalId) { + $intervalId[1] = false; + } /** * Runs a function immediately at the next iteration of the loop. + * + * @return void */ - public function nextTick(callable $cb) - { + function nextTick(callable $cb) { + $this->nextTick[] = $cb; + } + /** * Adds a read stream. * @@ -109,11 +118,13 @@ class Loop * prevent the eventloop from never stopping. * * @param resource $stream + * @return void */ - public function addReadStream($stream, callable $cb) - { - $this->readStreams[(int) $stream] = $stream; - $this->readCallbacks[(int) $stream] = $cb; + function addReadStream($stream, callable $cb) { + + $this->readStreams[(int)$stream] = $stream; + $this->readCallbacks[(int)$stream] = $cb; + } /** @@ -126,53 +137,65 @@ class Loop * prevent the eventloop from never stopping. * * @param resource $stream + * @return void */ - public function addWriteStream($stream, callable $cb) - { - $this->writeStreams[(int) $stream] = $stream; - $this->writeCallbacks[(int) $stream] = $cb; + function addWriteStream($stream, callable $cb) { + + $this->writeStreams[(int)$stream] = $stream; + $this->writeCallbacks[(int)$stream] = $cb; + } /** * Stop watching a stream for reads. * * @param resource $stream + * @return void */ - public function removeReadStream($stream) - { + function removeReadStream($stream) { + unset( - $this->readStreams[(int) $stream], - $this->readCallbacks[(int) $stream] + $this->readStreams[(int)$stream], + $this->readCallbacks[(int)$stream] ); + } /** * Stop watching a stream for writes. * * @param resource $stream + * @return void */ - public function removeWriteStream($stream) - { + function removeWriteStream($stream) { + unset( - $this->writeStreams[(int) $stream], - $this->writeCallbacks[(int) $stream] + $this->writeStreams[(int)$stream], + $this->writeCallbacks[(int)$stream] ); + } + /** * Runs the loop. * - * This function will run continuously, until there's no more events to + * This function will run continiously, until there's no more events to * handle. + * + * @return void */ - public function run() - { + function run() { + $this->running = true; do { + $hasEvents = $this->tick(true); + } while ($this->running && $hasEvents); $this->running = false; + } /** @@ -187,8 +210,8 @@ class Loop * This function will return true if there are _any_ events left in the * loop after the tick. */ - public function tick(bool $block = false): bool - { + function tick(bool $block = false) : bool { + $this->runNextTicks(); $nextTimeout = $this->runTimers(); @@ -209,15 +232,19 @@ class Loop $this->runStreams($streamWait); - return $this->readStreams || $this->writeStreams || $this->nextTick || $this->timers; + return ($this->readStreams || $this->writeStreams || $this->nextTick || $this->timers); + } /** - * Stops a running eventloop. + * Stops a running eventloop + * + * @return void */ - public function stop() - { + function stop() { + $this->running = false; + } /** @@ -225,14 +252,15 @@ class Loop * * return void */ - protected function runNextTicks() - { + protected function runNextTicks() { + $nextTick = $this->nextTick; $this->nextTick = []; foreach ($nextTick as $cb) { $cb(); } + } /** @@ -245,8 +273,8 @@ class Loop * * @return float|null */ - protected function runTimers() - { + protected function runTimers() { + $now = microtime(true); while (($timer = array_pop($this->timers)) && $timer[0] < $now) { $timer[1](); @@ -254,9 +282,9 @@ class Loop // Add the last timer back to the array. if ($timer) { $this->timers[] = $timer; - return max(0, $timer[0] - microtime(true)); } + } /** @@ -267,31 +295,36 @@ class Loop * * @param float|null timeout */ - protected function runStreams($timeout) - { + protected function runStreams($timeout) { + if ($this->readStreams || $this->writeStreams) { + $read = $this->readStreams; $write = $this->writeStreams; $except = null; - if (stream_select($read, $write, $except, (null === $timeout) ? null : 0, $timeout ? (int) ($timeout * 1000000) : 0)) { + if (stream_select($read, $write, $except, ($timeout === null) ? null : 0, $timeout ? (int)($timeout * 1000000) : 0)) { + // See PHP Bug https://bugs.php.net/bug.php?id=62452 // Fixed in PHP7 foreach ($read as $readStream) { - $readCb = $this->readCallbacks[(int) $readStream]; + $readCb = $this->readCallbacks[(int)$readStream]; $readCb(); } foreach ($write as $writeStream) { - $writeCb = $this->writeCallbacks[(int) $writeStream]; + $writeCb = $this->writeCallbacks[(int)$writeStream]; $writeCb(); } + } + } elseif ($this->running && ($this->nextTick || $this->timers)) { - usleep(null !== $timeout ? intval($timeout * 1000000) : 200000); + usleep($timeout !== null ? intval($timeout * 1000000) : 200000); } + } /** - * Is the main loop active. + * Is the main loop active * * @var bool */ @@ -328,14 +361,16 @@ class Loop /** * List of read callbacks, indexed by stream id. * - * @var callable[] + * @var callback[] */ protected $readCallbacks = []; /** * List of write callbacks, indexed by stream id. * - * @var callable[] + * @var callback[] */ protected $writeCallbacks = []; + + } diff --git a/vendor/sabre/event/lib/Loop/functions.php b/vendor/sabre/event/lib/Loop/functions.php index bf4d933f2..b5884b2b6 100644 --- a/vendor/sabre/event/lib/Loop/functions.php +++ b/vendor/sabre/event/lib/Loop/functions.php @@ -1,15 +1,16 @@ -<?php - -declare(strict_types=1); +<?php declare (strict_types=1); namespace Sabre\Event\Loop; /** * Executes a function after x seconds. + * + * @return void */ -function setTimeout(callable $cb, float $timeout) -{ +function setTimeout(callable $cb, float $timeout) { + instance()->setTimeout($cb, $timeout); + } /** @@ -18,27 +19,35 @@ function setTimeout(callable $cb, float $timeout) * The value this function returns can be used to stop the interval with * clearInterval. */ -function setInterval(callable $cb, float $timeout): array -{ +function setInterval(callable $cb, float $timeout) : array { + return instance()->setInterval($cb, $timeout); + } /** * Stops a running interval. + * + * @return void */ -function clearInterval(array $intervalId) -{ +function clearInterval(array $intervalId) { + instance()->clearInterval($intervalId); + } /** * Runs a function immediately at the next iteration of the loop. + * + * @return void */ -function nextTick(callable $cb) -{ +function nextTick(callable $cb) { + instance()->nextTick($cb); + } + /** * Adds a read stream. * @@ -49,10 +58,12 @@ function nextTick(callable $cb) * prevent the eventloop from never stopping. * * @param resource $stream + * @return void */ -function addReadStream($stream, callable $cb) -{ +function addReadStream($stream, callable $cb) { + instance()->addReadStream($stream, $cb); + } /** @@ -65,41 +76,51 @@ function addReadStream($stream, callable $cb) * prevent the eventloop from never stopping. * * @param resource $stream + * @return void */ -function addWriteStream($stream, callable $cb) -{ +function addWriteStream($stream, callable $cb) { + instance()->addWriteStream($stream, $cb); + } /** * Stop watching a stream for reads. * * @param resource $stream + * @return void */ -function removeReadStream($stream) -{ +function removeReadStream($stream) { + instance()->removeReadStream($stream); + } /** * Stop watching a stream for writes. * * @param resource $stream + * @return void */ -function removeWriteStream($stream) -{ +function removeWriteStream($stream) { + instance()->removeWriteStream($stream); + } + /** * Runs the loop. * - * This function will run continuously, until there's no more events to + * This function will run continiously, until there's no more events to * handle. + * + * @return void */ -function run() -{ +function run() { + instance()->run(); + } /** @@ -114,30 +135,34 @@ function run() * This function will return true if there are _any_ events left in the * loop after the tick. */ -function tick(bool $block = false): bool -{ +function tick(bool $block = false) : bool { + return instance()->tick($block); + } /** - * Stops a running eventloop. + * Stops a running eventloop + * + * @return void */ -function stop() -{ +function stop() { + instance()->stop(); + } /** * Retrieves or sets the global Loop object. */ -function instance(Loop $newLoop = null): Loop -{ +function instance(Loop $newLoop = null) : Loop { + static $loop; if ($newLoop) { $loop = $newLoop; } elseif (!$loop) { $loop = new Loop(); } - return $loop; + } |