mirror of
https://github.com/danog/amp.git
synced 2025-01-22 05:11:42 +01:00
More type declarations in loop component
This commit is contained in:
parent
1929715b97
commit
ca30af4d22
18
lib/Loop.php
18
lib/Loop.php
@ -80,7 +80,7 @@ final class Loop {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public static function defer(callable $callback, $data = null) {
|
||||
public static function defer(callable $callback, $data = null): string {
|
||||
return self::$driver->defer(wrap($callback), $data);
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ final class Loop {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public static function delay(int $delay, callable $callback, $data = null) {
|
||||
public static function delay(int $delay, callable $callback, $data = null): string {
|
||||
return self::$driver->delay($delay, wrap($callback), $data);
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ final class Loop {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public static function repeat(int $interval, callable $callback, $data = null) {
|
||||
public static function repeat(int $interval, callable $callback, $data = null): string {
|
||||
return self::$driver->repeat($interval, wrap($callback), $data);
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ final class Loop {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public static function onReadable($stream, callable $callback, $data = null) {
|
||||
public static function onReadable($stream, callable $callback, $data = null): string {
|
||||
return self::$driver->onReadable($stream, wrap($callback), $data);
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ final class Loop {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public static function onWritable($stream, callable $callback, $data = null) {
|
||||
public static function onWritable($stream, callable $callback, $data = null): string {
|
||||
return self::$driver->onWritable($stream, wrap($callback), $data);
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ final class Loop {
|
||||
*
|
||||
* @throws UnsupportedFeatureException If signal handling is not supported.
|
||||
*/
|
||||
public static function onSignal(int $signo, callable $callback, $data = null) {
|
||||
public static function onSignal(int $signo, callable $callback, $data = null): string {
|
||||
return self::$driver->onSignal($signo, wrap($callback), $data);
|
||||
}
|
||||
|
||||
@ -341,16 +341,16 @@ final class Loop {
|
||||
*
|
||||
* @return array Statistics about the loop in the described format.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
public static function getInfo(): array {
|
||||
return self::$driver->getInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the event loop driver that is in scope.
|
||||
*
|
||||
* @return Driver|null
|
||||
* @return Driver
|
||||
*/
|
||||
public static function get() {
|
||||
public static function get(): Driver {
|
||||
return self::$driver;
|
||||
}
|
||||
}
|
||||
|
@ -20,16 +20,16 @@ abstract class Driver {
|
||||
/** @var string */
|
||||
private $nextId = "a";
|
||||
|
||||
/** @var \Amp\Loop\Internal\Watcher[] */
|
||||
/** @var \Amp\Internal\Watcher[] */
|
||||
private $watchers = [];
|
||||
|
||||
/** @var \Amp\Loop\Internal\Watcher[] */
|
||||
/** @var \Amp\Internal\Watcher[] */
|
||||
private $enableQueue = [];
|
||||
|
||||
/** @var \Amp\Loop\Internal\Watcher[] */
|
||||
/** @var \Amp\Internal\Watcher[] */
|
||||
private $deferQueue = [];
|
||||
|
||||
/** @var \Amp\Loop\Internal\Watcher[] */
|
||||
/** @var \Amp\Internal\Watcher[] */
|
||||
private $nextTickQueue = [];
|
||||
|
||||
/** @var callable|null */
|
||||
@ -122,7 +122,7 @@ abstract class Driver {
|
||||
/**
|
||||
* Activates (enables) all the given watchers.
|
||||
*
|
||||
* @param \Amp\Loop\Internal\Watcher[] $watchers
|
||||
* @param \Amp\Internal\Watcher[] $watchers
|
||||
*/
|
||||
abstract protected function activate(array $watchers);
|
||||
|
||||
@ -131,7 +131,7 @@ abstract class Driver {
|
||||
*
|
||||
* @param bool $blocking
|
||||
*/
|
||||
abstract protected function dispatch($blocking);
|
||||
abstract protected function dispatch(bool $blocking);
|
||||
|
||||
/**
|
||||
* Stop the event loop.
|
||||
@ -160,7 +160,7 @@ abstract class Driver {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public function defer(callable $callback, $data = null) {
|
||||
public function defer(callable $callback, $data = null): string {
|
||||
$watcher = new Watcher;
|
||||
$watcher->type = Watcher::DEFER;
|
||||
$watcher->id = $this->nextId++;
|
||||
@ -189,7 +189,7 @@ abstract class Driver {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public function delay(int $delay, callable $callback, $data = null) {
|
||||
public function delay(int $delay, callable $callback, $data = null): string {
|
||||
if ($delay < 0) {
|
||||
throw new \InvalidArgumentException("Delay must be greater than or equal to zero");
|
||||
}
|
||||
@ -223,7 +223,7 @@ abstract class Driver {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public function repeat(int $interval, callable $callback, $data = null) {
|
||||
public function repeat(int $interval, callable $callback, $data = null): string {
|
||||
if ($interval < 0) {
|
||||
throw new \InvalidArgumentException("Interval must be greater than or equal to zero");
|
||||
}
|
||||
@ -260,7 +260,7 @@ abstract class Driver {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public function onReadable($stream, callable $callback, $data = null) {
|
||||
public function onReadable($stream, callable $callback, $data = null): string {
|
||||
$watcher = new Watcher;
|
||||
$watcher->type = Watcher::READABLE;
|
||||
$watcher->id = $this->nextId++;
|
||||
@ -293,7 +293,7 @@ abstract class Driver {
|
||||
*
|
||||
* @return string An unique identifier that can be used to cancel, enable or disable the watcher.
|
||||
*/
|
||||
public function onWritable($stream, callable $callback, $data = null) {
|
||||
public function onWritable($stream, callable $callback, $data = null): string {
|
||||
$watcher = new Watcher;
|
||||
$watcher->type = Watcher::WRITABLE;
|
||||
$watcher->id = $this->nextId++;
|
||||
@ -327,7 +327,7 @@ abstract class Driver {
|
||||
*
|
||||
* @throws UnsupportedFeatureException If signal handling is not supported.
|
||||
*/
|
||||
public function onSignal(int $signo, callable $callback, $data = null) {
|
||||
public function onSignal(int $signo, callable $callback, $data = null): string {
|
||||
$watcher = new Watcher;
|
||||
$watcher->type = Watcher::SIGNAL;
|
||||
$watcher->id = $this->nextId++;
|
||||
@ -443,7 +443,7 @@ abstract class Driver {
|
||||
/**
|
||||
* Deactivates (disables) the given watcher.
|
||||
*
|
||||
* @param \Amp\Loop\Internal\Watcher $watcher
|
||||
* @param \Amp\Internal\Watcher $watcher
|
||||
*/
|
||||
abstract protected function deactivate(Watcher $watcher);
|
||||
|
||||
@ -582,7 +582,7 @@ abstract class Driver {
|
||||
*
|
||||
* @return array Statistics about the loop in the described format.
|
||||
*/
|
||||
public function getInfo() {
|
||||
public function getInfo(): array {
|
||||
$watchers = [
|
||||
"referenced" => 0,
|
||||
"unreferenced" => 0,
|
||||
|
@ -64,7 +64,7 @@ class EvLoop extends Driver {
|
||||
unset($this->events[$watcherId]);
|
||||
}
|
||||
|
||||
public static function supported() {
|
||||
public static function supported(): bool {
|
||||
return \extension_loaded("ev");
|
||||
}
|
||||
|
||||
@ -116,14 +116,14 @@ class EvLoop extends Driver {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHandle() {
|
||||
public function getHandle(): \EvLoop {
|
||||
return $this->handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function dispatch($blocking) {
|
||||
protected function dispatch(bool $blocking) {
|
||||
$this->handle->run($blocking ? \Ev::RUN_ONCE : \Ev::RUN_ONCE | \Ev::RUN_NOWAIT);
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ class EventLoop extends Driver {
|
||||
}
|
||||
}
|
||||
|
||||
public static function supported() {
|
||||
public static function supported(): bool {
|
||||
return \extension_loaded("event");
|
||||
}
|
||||
|
||||
@ -111,14 +111,14 @@ class EventLoop extends Driver {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHandle() {
|
||||
public function getHandle(): \EventBase {
|
||||
return $this->handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function dispatch($blocking) {
|
||||
protected function dispatch(bool $blocking) {
|
||||
$this->handle->loop($blocking ? \EventBase::LOOP_ONCE : \EventBase::LOOP_ONCE | \EventBase::LOOP_NONBLOCK);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class NativeLoop extends Driver {
|
||||
* @throws \Amp\Loop\UnsupportedFeatureException If the pcntl extension is not available.
|
||||
* @throws \RuntimeException If creating the backend signal handler fails.
|
||||
*/
|
||||
public function onSignal(int $signo, callable $callback, $data = null) {
|
||||
public function onSignal(int $signo, callable $callback, $data = null): string {
|
||||
if (!$this->signalHandling) {
|
||||
throw new UnsupportedFeatureException("Signal handling requires the pcntl extension");
|
||||
}
|
||||
@ -55,7 +55,7 @@ class NativeLoop extends Driver {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function dispatch($blocking) {
|
||||
protected function dispatch(bool $blocking) {
|
||||
$this->selectStreams(
|
||||
$this->readStreams,
|
||||
$this->writeStreams,
|
||||
@ -270,7 +270,7 @@ class NativeLoop extends Driver {
|
||||
/**
|
||||
* @param int $signo
|
||||
*/
|
||||
private function handleSignal($signo) {
|
||||
private function handleSignal(int $signo) {
|
||||
foreach ($this->signalWatchers[$signo] as $watcher) {
|
||||
if (!isset($this->signalWatchers[$signo][$watcher->id])) {
|
||||
continue;
|
||||
|
@ -96,7 +96,7 @@ class UvLoop extends Driver {
|
||||
unset($this->events[$watcherId]);
|
||||
}
|
||||
|
||||
public static function supported() {
|
||||
public static function supported(): bool {
|
||||
return \extension_loaded("uv");
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ class UvLoop extends Driver {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function dispatch($blocking) {
|
||||
protected function dispatch(bool $blocking) {
|
||||
\uv_run($this->handle, $blocking ? \UV::RUN_ONCE : \UV::RUN_NOWAIT);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user