Skip to content

Commit 86b5f82

Browse files
committed
Update usage examples
1 parent 75a59f1 commit 86b5f82

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ single [`run()`](#run) call that is controlled by the user.
4848
Here is an async HTTP server built with just the event loop.
4949

5050
```php
51+
<?php
52+
5153
use React\EventLoop\Loop;
5254

55+
require __DIR__ . '/vendor/autoload.php';
56+
5357
$server = stream_socket_server('tcp://127.0.0.1:8080');
5458
stream_set_blocking($server, false);
5559

@@ -81,14 +85,15 @@ See also the [examples](examples).
8185
## Usage
8286

8387
As of `v1.2.0`, typical applications would use the [`Loop` object](#loop)
84-
to use the currently active event loop instance like this:
88+
to use the currently active event loop like this:
8589

8690
```php
8791
use React\EventLoop\Loop;
8892

8993
$timer = Loop::addPeriodicTimer(0.1, function () {
90-
echo "Tick" . PHP_EOL;
94+
echo 'Tick' . PHP_EOL;
9195
});
96+
9297
Loop::addTimer(1.0, function () use ($timer) {
9398
Loop::cancelTimer($timer);
9499
echo 'Done' . PHP_EOL;
@@ -105,8 +110,9 @@ program like this:
105110
$loop = React\EventLoop\Loop::get(); // or deprecated React\EventLoop\Factory::create();
106111

107112
$timer = $loop->addPeriodicTimer(0.1, function () {
108-
echo "Tick" . PHP_EOL;
113+
echo 'Tick' . PHP_EOL;
109114
});
115+
110116
$loop->addTimer(1.0, function () use ($loop, $timer) {
111117
$loop->cancelTimer($timer);
112118
echo 'Done' . PHP_EOL;
@@ -163,7 +169,7 @@ like this:
163169
use React\EventLoop\Loop;
164170

165171
$timer = Loop::addPeriodicTimer(0.1, function () {
166-
echo 'tick!' . PHP_EOL;
172+
echo 'Tick' . PHP_EOL;
167173
});
168174

169175
Loop::addTimer(1.0, function () use ($timer) {

examples/02-periodic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require __DIR__ . '/../vendor/autoload.php';
66

77
$timer = Loop::addPeriodicTimer(0.1, function () {
8-
echo 'tick!' . PHP_EOL;
8+
echo 'Tick' . PHP_EOL;
99
});
1010

1111
Loop::addTimer(1.0, function () use ($timer) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy