Skip to content

Improve documentation regarding deprecated Factory #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update usage examples
  • Loading branch information
clue committed Jun 30, 2021
commit 86b5f82e743bc34a55c0c3497e038461072609a9
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ single [`run()`](#run) call that is controlled by the user.
Here is an async HTTP server built with just the event loop.

```php
<?php

use React\EventLoop\Loop;

require __DIR__ . '/vendor/autoload.php';

$server = stream_socket_server('tcp://127.0.0.1:8080');
stream_set_blocking($server, false);

Expand Down Expand Up @@ -81,14 +85,15 @@ See also the [examples](examples).
## Usage

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

```php
use React\EventLoop\Loop;

$timer = Loop::addPeriodicTimer(0.1, function () {
echo "Tick" . PHP_EOL;
echo 'Tick' . PHP_EOL;
});

Loop::addTimer(1.0, function () use ($timer) {
Loop::cancelTimer($timer);
echo 'Done' . PHP_EOL;
Expand All @@ -105,8 +110,9 @@ program like this:
$loop = React\EventLoop\Loop::get(); // or deprecated React\EventLoop\Factory::create();

$timer = $loop->addPeriodicTimer(0.1, function () {
echo "Tick" . PHP_EOL;
echo 'Tick' . PHP_EOL;
});

$loop->addTimer(1.0, function () use ($loop, $timer) {
$loop->cancelTimer($timer);
echo 'Done' . PHP_EOL;
Expand Down Expand Up @@ -163,7 +169,7 @@ like this:
use React\EventLoop\Loop;

$timer = Loop::addPeriodicTimer(0.1, function () {
echo 'tick!' . PHP_EOL;
echo 'Tick' . PHP_EOL;
});

Loop::addTimer(1.0, function () use ($timer) {
Expand Down
2 changes: 1 addition & 1 deletion examples/02-periodic.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require __DIR__ . '/../vendor/autoload.php';

$timer = Loop::addPeriodicTimer(0.1, function () {
echo 'tick!' . PHP_EOL;
echo 'Tick' . PHP_EOL;
});

Loop::addTimer(1.0, function () use ($timer) {
Expand Down
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