1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 13:21:16 +01:00

Fast return on void watcher callback

This commit is contained in:
Aaron Piotrowski 2017-03-12 12:03:13 -05:00
parent cd4328ab48
commit f040e8801e
5 changed files with 55 additions and 1 deletions

View File

@ -111,6 +111,10 @@ abstract class Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $watcher->data);
if ($result === null) {
continue;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {

View File

@ -39,6 +39,10 @@ class EvDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $watcher->value, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
@ -61,6 +65,10 @@ class EvDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
@ -79,6 +87,10 @@ class EvDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $watcher->value, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {

View File

@ -36,6 +36,10 @@ class EventDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $watcher->value, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
@ -51,10 +55,14 @@ class EventDriver extends Driver {
if ($watcher->type & Watcher::DELAY) {
$this->cancel($watcher->id);
}
$callback = $watcher->callback;
$result = $callback($watcher->id, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
@ -70,6 +78,10 @@ class EventDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $watcher->value, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {

View File

@ -147,6 +147,10 @@ class NativeDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $stream, $watcher->data);
if ($result === null) {
continue;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
@ -171,6 +175,10 @@ class NativeDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $stream, $watcher->data);
if ($result === null) {
continue;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
@ -314,8 +322,14 @@ class NativeDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $signo, $watcher->data);
if ($result === null) {
continue;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
$result = adapt($result);
}
if ($result instanceof Promise) {

View File

@ -61,6 +61,10 @@ class UvDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $resource, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
@ -83,6 +87,10 @@ class UvDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {
@ -100,6 +108,10 @@ class UvDriver extends Driver {
$callback = $watcher->callback;
$result = $callback($watcher->id, $signo, $watcher->data);
if ($result === null) {
return;
}
if ($result instanceof \Generator) {
$result = new Coroutine($result);
} elseif ($result instanceof ReactPromise) {