-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from clue-labs/default-loop
Simplify usage by supporting new default loop
- Loading branch information
Showing
10 changed files
with
50 additions
and
59 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
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,38 +1,35 @@ | ||
<?php | ||
|
||
use Clue\React\Stdio\Stdio; | ||
use React\EventLoop\Loop; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
|
||
$stdio = new Stdio($loop); | ||
$stdio = new Stdio(); | ||
|
||
$stdio->write('Will print periodic messages until you submit anything' . PHP_EOL); | ||
|
||
// add some periodic noise | ||
$timer = $loop->addPeriodicTimer(0.5, function () use ($stdio) { | ||
$timer = Loop::addPeriodicTimer(0.5, function () use ($stdio) { | ||
$stdio->write(date('Y-m-d H:i:s') . ' hello' . PHP_EOL); | ||
}); | ||
|
||
// react to commands the user entered | ||
$stdio->on('data', function ($line) use ($stdio, $loop, $timer) { | ||
$stdio->on('data', function ($line) use ($stdio, $timer) { | ||
$stdio->write('you just said: ' . addcslashes($line, "\0..\37") . ' (' . strlen($line) . ')' . PHP_EOL); | ||
|
||
$loop->cancelTimer($timer); | ||
Loop::cancelTimer($timer); | ||
$stdio->end(); | ||
}); | ||
|
||
// cancel periodic timer if STDIN closed | ||
$stdio->on('end', function () use ($stdio, $loop, $timer) { | ||
$loop->cancelTimer($timer); | ||
$stdio->on('end', function () use ($stdio, $timer) { | ||
Loop::cancelTimer($timer); | ||
$stdio->end(); | ||
}); | ||
|
||
// input already closed on program start, exit immediately | ||
if (!$stdio->isReadable()) { | ||
$loop->cancelTimer($timer); | ||
Loop::cancelTimer($timer); | ||
$stdio->end(); | ||
} | ||
|
||
$loop->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
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