mirror of
https://github.com/danog/amp.git
synced 2025-01-21 21:01:16 +01:00
Use anonymous classes
This commit is contained in:
parent
446eded441
commit
7cb09edf29
@ -256,9 +256,6 @@ class NativeReactor implements Reactor {
|
||||
public function once(callable $callback, int $msDelay, array $options = []): string {
|
||||
assert(($msDelay >= 0), "\$msDelay at Argument 2 expects integer >= 0");
|
||||
|
||||
// @TODO Replace stdclass with anon class once merged into php-src/master
|
||||
$watcher = new \StdClass;
|
||||
/*
|
||||
$watcher = new class extends Watcher {
|
||||
// Inherited:
|
||||
// public $id;
|
||||
@ -269,7 +266,6 @@ class NativeReactor implements Reactor {
|
||||
public $msDelay;
|
||||
public $nextExecutionAt;
|
||||
}
|
||||
*/
|
||||
|
||||
$watcher->id = $watcherId = $this->lastWatcherId++;
|
||||
$watcher->type = Watcher::TIMER_ONCE;
|
||||
@ -301,9 +297,6 @@ class NativeReactor implements Reactor {
|
||||
$msDelay = $options["msDelay"] ?? $msInterval;
|
||||
assert(($msDelay >= 0), "msDelay option expects integer >= 0");
|
||||
|
||||
// @TODO Replace stdclass with anon class once merged into php-src/master
|
||||
$watcher = new \StdClass;
|
||||
/*
|
||||
$watcher = new class extends Watcher {
|
||||
// Inherited:
|
||||
// public $id;
|
||||
@ -315,7 +308,6 @@ class NativeReactor implements Reactor {
|
||||
public $msInterval;
|
||||
public $nextExecutionAt;
|
||||
}
|
||||
*/
|
||||
|
||||
$watcher->id = $watcherId = $this->lastWatcherId++;
|
||||
$watcher->type = Watcher::TIMER_REPEAT;
|
||||
@ -355,9 +347,6 @@ class NativeReactor implements Reactor {
|
||||
}
|
||||
|
||||
private function registerIoWatcher($stream, $callback, $options, $type): string {
|
||||
// @TODO Replace stdclass with anon class once merged into php-src/master
|
||||
$watcher = new \StdClass;
|
||||
/*
|
||||
$watcher = new class extends Watcher {
|
||||
// Inherited:
|
||||
// public $id;
|
||||
@ -368,7 +357,6 @@ class NativeReactor implements Reactor {
|
||||
public $streamId;
|
||||
public $stream;
|
||||
}
|
||||
*/
|
||||
|
||||
$watcher->id = $watcherId = $this->lastWatcherId++;
|
||||
$watcher->type = $type;
|
||||
@ -405,7 +393,6 @@ class NativeReactor implements Reactor {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function enable(string $watcherId) {
|
||||
// @TODO should this throw?
|
||||
if (!isset($this->watchers[$watcherId])) {
|
||||
return;
|
||||
}
|
||||
|
@ -130,9 +130,6 @@ class UvReactor implements SignalReactor {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function immediately(callable $callback, array $options = []): string {
|
||||
// @TODO Replace stdclass with anon class once merged into php-src/master
|
||||
$watcher = new \StdClass;
|
||||
/*
|
||||
$watcher = new class extends Watcher {
|
||||
// Inherited:
|
||||
// public $id;
|
||||
@ -143,7 +140,6 @@ class UvReactor implements SignalReactor {
|
||||
public $msDelay;
|
||||
public $nextExecutionAt;
|
||||
}
|
||||
*/
|
||||
|
||||
$watcher->id = $watcherId = $this->lastWatcherId++;
|
||||
$watcher->type = Watcher::IMMEDIATE;
|
||||
@ -189,9 +185,6 @@ class UvReactor implements SignalReactor {
|
||||
|
||||
private function registerTimer(callable $callback, int $msDelay, int $msInterval, array $options): string {
|
||||
$this->enabledWatcherCount++;
|
||||
// @TODO Replace stdclass with anon class once merged into php-src/master
|
||||
$watcher = new \StdClass;
|
||||
/*
|
||||
$watcher = new class extends Watcher {
|
||||
// Inherited:
|
||||
// public $id;
|
||||
@ -203,7 +196,6 @@ class UvReactor implements SignalReactor {
|
||||
public $msDelay;
|
||||
public $msInterval;
|
||||
};
|
||||
*/
|
||||
|
||||
$isRepeating = ($msInterval !== -1);
|
||||
|
||||
@ -273,9 +265,6 @@ class UvReactor implements SignalReactor {
|
||||
}
|
||||
|
||||
private function watchStream($stream, callable $callback, int $type, array $options): string {
|
||||
// @TODO Replace stdclass with anon class once merged into php-src/master
|
||||
$watcher = new \StdClass;
|
||||
/*
|
||||
$watcher = new class extends Watcher {
|
||||
// Inherited:
|
||||
// public $id;
|
||||
@ -288,7 +277,6 @@ class UvReactor implements SignalReactor {
|
||||
public $streamId;
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
$this->watchers[$watcherId] = $watcher;
|
||||
|
||||
@ -341,9 +329,6 @@ class UvReactor implements SignalReactor {
|
||||
|
||||
$streamId = (int) $stream;
|
||||
|
||||
// @TODO Replace stdclass with anon class once merged into php-src/master
|
||||
$poll = new \StdClass;
|
||||
/*
|
||||
$poll = new class {
|
||||
use Struct;
|
||||
public $flags;
|
||||
@ -353,7 +338,6 @@ class UvReactor implements SignalReactor {
|
||||
public $writers = [];
|
||||
public $disable = [];
|
||||
};
|
||||
*/
|
||||
$this->streamIdPollMap[$streamId] = $poll;
|
||||
|
||||
$poll->flags = 0;
|
||||
@ -397,9 +381,6 @@ class UvReactor implements SignalReactor {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function onSignal(int $signo, callable $func, array $options = []): string {
|
||||
// @TODO Replace stdclass with anon class once merged into php-src/master
|
||||
$watcher = new \StdClass;
|
||||
/*
|
||||
$watcher = new class extends Watcher {
|
||||
// Inherited:
|
||||
// public $id;
|
||||
@ -410,7 +391,6 @@ class UvReactor implements SignalReactor {
|
||||
public $signo;
|
||||
public $uvHandle;
|
||||
};
|
||||
*/
|
||||
$watcher->id = $watcherId = $this->lastWatcherId++;
|
||||
$watcher->type = Watcher::SIGNAL;
|
||||
$watcher->callback = $this->wrapSignalCallback($watcher, $func);
|
||||
|
@ -479,9 +479,6 @@ function coroutine(callable $func, Reactor $reactor = null, callable $promisifie
|
||||
* error occurs during coroutine resolution the promise fails.
|
||||
*/
|
||||
function resolve(\Generator $generator, Reactor $reactor = null, callable $promisifier = null): Promise {
|
||||
// @TODO Replace stdclass with anon class once merged into php-src
|
||||
$cs = new \StdClass;
|
||||
/*
|
||||
$cs = new class {
|
||||
use Struct;
|
||||
public $reactor;
|
||||
@ -489,7 +486,6 @@ function resolve(\Generator $generator, Reactor $reactor = null, callable $promi
|
||||
public $generator;
|
||||
public $promisifier;
|
||||
};
|
||||
*/
|
||||
$cs->reactor = $reactor ?: getReactor();
|
||||
$cs->promisor = new Future;
|
||||
$cs->generator = $generator;
|
||||
|
Loading…
x
Reference in New Issue
Block a user