-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global event-loop accessor part four
- Loading branch information
1 parent
8bd064c
commit 22c9972
Showing
18 changed files
with
233 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
use React\EventLoop\Loop; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$loop->addTimer(0.8, function () { | ||
Loop::get()->addTimer(0.8, function () { | ||
echo 'world!' . PHP_EOL; | ||
}); | ||
|
||
$loop->addTimer(0.3, function () { | ||
Loop::get()->addTimer(0.3, function () { | ||
echo 'hello '; | ||
}); | ||
|
||
$loop->run(); | ||
Loop::get()->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
use React\EventLoop\Loop; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$timer = $loop->addPeriodicTimer(0.1, function () { | ||
$timer = Loop::get()->addPeriodicTimer(0.1, function () { | ||
echo 'tick!' . PHP_EOL; | ||
}); | ||
|
||
$loop->addTimer(1.0, function () use ($loop, $timer) { | ||
$loop->cancelTimer($timer); | ||
Loop::get()->addTimer(1.0, function () use ($timer) { | ||
Loop::get()->cancelTimer($timer); | ||
echo 'Done' . PHP_EOL; | ||
}); | ||
|
||
$loop->run(); | ||
Loop::get()->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
use React\EventLoop\Loop; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$loop->futureTick(function () { | ||
Loop::get()->futureTick(function () { | ||
echo 'b'; | ||
}); | ||
$loop->futureTick(function () { | ||
Loop::get()->futureTick(function () { | ||
echo 'c'; | ||
}); | ||
echo 'a'; | ||
|
||
$loop->run(); | ||
Loop::get()->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
<?php | ||
|
||
use React\EventLoop\Loop; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
if (!defined('SIGINT')) { | ||
fwrite(STDERR, 'Not supported on your platform (ext-pcntl missing or Windows?)' . PHP_EOL); | ||
exit(1); | ||
} | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
|
||
$loop->addSignal(SIGINT, $func = function ($signal) use ($loop, &$func) { | ||
Loop::get()->addSignal(SIGINT, $func = function ($signal) use (&$func) { | ||
echo 'Signal: ', (string)$signal, PHP_EOL; | ||
$loop->removeSignal(SIGINT, $func); | ||
Loop::get()->removeSignal(SIGINT, $func); | ||
}); | ||
|
||
echo 'Listening for SIGINT. Use "kill -SIGINT ' . getmypid() . '" or CTRL+C' . PHP_EOL; | ||
|
||
$loop->run(); | ||
Loop::get()->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
<?php | ||
|
||
use React\EventLoop\Factory; | ||
use React\EventLoop\Loop; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$loop = Factory::create(); | ||
|
||
$n = isset($argv[1]) ? (int)$argv[1] : 1000 * 100; | ||
|
||
for ($i = 0; $i < $n; ++$i) { | ||
$loop->futureTick(function () { }); | ||
Loop::get()->futureTick(function () { }); | ||
} | ||
|
||
$loop->run(); | ||
Loop::get()->run(); |
Oops, something went wrong.