mirror of
https://github.com/danog/amp.git
synced 2024-11-30 04:29:08 +01:00
094899a74b
This option determines if the watcher will keep the run() loop from returning. By default all watchers set "keep_alive" => true. Setting this value to false is ideal for registering non-crucial watchers (e.g. cache invalidation timers) that should run for the life of the program but shouldn't prevent the event loop from returning if all essential tasks have completed. <?php echo "before run\n"; run(function () { immediately(function () { echo "immediately\n"; }); once(function () { echo "once\n"; }, 100, ["keep_alive" => false]); repeat(function () { echo "repeat\n"; }, 500, ["keep_alive" => false]); echo "onStart end\n"; }); echo "after run\n"; The above snippet will have the following output: before run immediately after run The Amp\info() function now also reports the number of keep_alive watchers currently registered via the "keep_alive" key.
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp\UvReactor;
|
|
|
|
class UvReactorTest extends ReactorTest {
|
|
protected function setUp() {
|
|
if (extension_loaded("uv")) {
|
|
\Amp\reactor($assign = new UvReactor);
|
|
} else {
|
|
$this->markTestSkipped(
|
|
"php-uv extension not loaded"
|
|
);
|
|
}
|
|
}
|
|
|
|
public function testGetLoop() {
|
|
$result = \Amp\reactor()->getLoop();
|
|
$this->assertInternalType("resource", $result);
|
|
}
|
|
|
|
public function testOnSignalWatcherKeepAliveRunResult() {
|
|
\Amp\run(function () {
|
|
\Amp\onSignal(\Uv::SIGUSR1, function () {
|
|
// empty
|
|
}, $options = ["keep_alive" => false]);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* We need to override the default ReactorTest function to use the correct signal constant
|
|
*/
|
|
public function provideRegistrationArgs() {
|
|
$result = [
|
|
["immediately", [function () {}]],
|
|
["once", [function () {}, 5000]],
|
|
["repeat", [function () {}, 5000]],
|
|
["onWritable", [\STDOUT, function () {}]],
|
|
["onReadable", [\STDIN, function () {}]],
|
|
];
|
|
|
|
if (\extension_loaded("uv")) {
|
|
$result[] = ["onSignal", [\Uv::SIGUSR1, function () {}]];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|