Skip to content

Commit

Permalink
Small improvements on examples (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
thgs authored Jan 7, 2024
1 parent 5aeaad2 commit 024369c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions examples/context.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
$timer = EventLoop::repeat(1, function () {
static $i;
$i = $i ? ++$i : 1;
print "Demonstrating how alive the parent is for the {$i}th time.\n";
$nth = $i . ([1 => 'st', 2 => 'nd', 3 => 'rd'][$i] ?? 'th');
print "Demonstrating how alive the parent is for the {$nth} time.\n";
});

try {
Expand All @@ -19,9 +20,9 @@
print "Waiting 2 seconds to send start data...\n";
delay(2);

$context->send("Start data"); // Data sent to child process, received on line 9 of blocking-process.php
$context->send("Start data"); // Data sent to child process, received on line 9 of contexts/blocking.php

printf("Received the following from child: %s\n", $context->receive()); // Sent on line 14 of blocking-process.php
printf("Received the following from child: %s\n", $context->receive()); // Sent on line 14 of blocking.php
printf("Process ended with value %d!\n", $context->join());
} finally {
EventLoop::cancel($timer);
Expand Down
7 changes: 4 additions & 3 deletions examples/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
$timer = EventLoop::repeat(1, function () {
static $i;
$i = $i ? ++$i : 1;
print "Demonstrating how alive the parent is for the {$i}th time.\n";
$nth = $i . ([1 => 'st', 2 => 'nd', 3 => 'rd'][$i] ?? 'th');
print "Demonstrating how alive the parent is for the {$nth} time.\n";
});

// This example is identical to context.php, but uses a ProcessContext to demonstrate piping STDOUT
Expand All @@ -27,9 +28,9 @@
print "Waiting 2 seconds to send start data...\n";
delay(2);

$context->send("Start data"); // Data sent to child process, received on line 9 of blocking-process.php
$context->send("Start data"); // Data sent to child process, received on line 9 of contexts/blocking.php

printf("Received the following from child: %s\n", $context->receive()); // Sent on line 14 of blocking-process.php
printf("Received the following from child: %s\n", $context->receive()); // Sent on line 14 of contexts/blocking.php
printf("Process ended with value %d!\n", $context->join());
} finally {
EventLoop::cancel($timer);
Expand Down

0 comments on commit 024369c

Please sign in to comment.