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.