Skip to content

Commit 01a2900

Browse files
committed
Improve documentation regarding deprecated Factory
1 parent 1a709e2 commit 01a2900

File tree

2 files changed

+52
-49
lines changed

2 files changed

+52
-49
lines changed

README.md

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ single [`run()`](#run) call that is controlled by the user.
1313

1414
* [Quickstart example](#quickstart-example)
1515
* [Usage](#usage)
16-
* [Loop](#loop)
17-
* [get()](#get)
18-
* [Factory](#factory)
19-
* [create()](#create)
20-
* [Loop implementations](#loop-implementations)
21-
* [StreamSelectLoop](#streamselectloop)
22-
* [ExtEventLoop](#exteventloop)
23-
* [ExtLibeventLoop](#extlibeventloop)
24-
* [ExtLibevLoop](#extlibevloop)
25-
* [ExtEvLoop](#extevloop)
26-
* [ExtUvLoop](#extuvloop)
27-
* [LoopInterface](#loopinterface)
28-
* [run()](#run)
29-
* [stop()](#stop)
30-
* [addTimer()](#addtimer)
31-
* [addPeriodicTimer()](#addperiodictimer)
32-
* [cancelTimer()](#canceltimer)
33-
* [futureTick()](#futuretick)
34-
* [addSignal()](#addsignal)
35-
* [removeSignal()](#removesignal)
36-
* [addReadStream()](#addreadstream)
37-
* [addWriteStream()](#addwritestream)
38-
* [removeReadStream()](#removereadstream)
39-
* [removeWriteStream()](#removewritestream)
16+
* [Loop](#loop)
17+
* [get()](#get)
18+
* [Factory](#factory)
19+
* [~~create()~~](#create)
20+
* [Loop implementations](#loop-implementations)
21+
* [StreamSelectLoop](#streamselectloop)
22+
* [ExtEventLoop](#exteventloop)
23+
* [ExtLibeventLoop](#extlibeventloop)
24+
* [ExtLibevLoop](#extlibevloop)
25+
* [ExtEvLoop](#extevloop)
26+
* [ExtUvLoop](#extuvloop)
27+
* [LoopInterface](#loopinterface)
28+
* [run()](#run)
29+
* [stop()](#stop)
30+
* [addTimer()](#addtimer)
31+
* [addPeriodicTimer()](#addperiodictimer)
32+
* [cancelTimer()](#canceltimer)
33+
* [futureTick()](#futuretick)
34+
* [addSignal()](#addsignal)
35+
* [removeSignal()](#removesignal)
36+
* [addReadStream()](#addreadstream)
37+
* [addWriteStream()](#addwritestream)
38+
* [removeReadStream()](#removereadstream)
39+
* [removeWriteStream()](#removewritestream)
4040
* [Install](#install)
4141
* [Tests](#tests)
4242
* [License](#license)
@@ -83,34 +83,29 @@ Typical applications use a single event loop which is created at the beginning
8383
and run at the end of the program.
8484

8585
```php
86-
// [1]
87-
$loop = React\EventLoop\Factory::create();
86+
$loop = React\EventLoop\Loop::get(); // or deprecated React\EventLoop\Factory::create();
8887

89-
// [2]
90-
$loop->addPeriodicTimer(1, function () {
91-
echo "Tick\n";
88+
$timer = $loop->addPeriodicTimer(0.1, function () {
89+
echo "Tick" . PHP_EOL;
90+
});
91+
$loop->addTimer(1.0, function () use ($loop, $timer) {
92+
$loop->cancelTimer($timer);
93+
echo 'Done' . PHP_EOL;
9294
});
9395

94-
$stream = new React\Stream\ReadableResourceStream(
95-
fopen('file.txt', 'r'),
96-
$loop
97-
);
98-
99-
// [3]
10096
$loop->run();
10197
```
10298

103-
1. The loop instance is created at the beginning of the program. A convenience
104-
factory [`React\EventLoop\Factory::create()`](#create) is provided by this library which
105-
picks the best available [loop implementation](#loop-implementations).
106-
2. The loop instance is used directly or passed to library and application code.
107-
In this example, a periodic timer is registered with the event loop which
108-
simply outputs `Tick` every second and a
109-
[readable stream](https://github.com/reactphp/stream#readableresourcestream)
110-
is created by using ReactPHP's
111-
[stream component](https://github.com/reactphp/stream) for demonstration
112-
purposes.
113-
3. The loop is run with a single [`$loop->run()`](#run) call at the end of the program.
99+
1. The event loop instance is created at the beginning of the program. This is
100+
implicitly done the first time you call the [`Loop` class](#loop) or
101+
explicitly when using the deprecated [`Factory::create() method`](#create)
102+
(or manually instantiating any of the [loop implementation](#loop-implementations)).
103+
2. The event loop is used directly or passed as an instance to library and
104+
application code. In this example, a periodic timer is registered with the
105+
event loop which simply outputs `Tick` every fraction of a second until another
106+
timer stops the periodic timer after a second.
107+
3. The event loop is run at the end of the program with a single [`run()`](#run)
108+
call at the end of the program.
114109

115110
### Loop
116111

@@ -139,13 +134,17 @@ Loop::get()->run();
139134
The `Factory` class exists as a convenient way to pick the best available
140135
[event loop implementation](#loop-implementations).
141136

142-
#### create()
137+
#### ~~create()~~
143138

144-
The `create(): LoopInterface` method can be used to create a new event loop
145-
instance:
139+
The deprecated `create(): LoopInterface` method can be used to
140+
create a new event loop instance:
146141

147142
```php
143+
// deprecated
148144
$loop = React\EventLoop\Factory::create();
145+
146+
// new
147+
$loop = React\EventLoop\Loop::get();
149148
```
150149

151150
This method always returns an instance implementing [`LoopInterface`](#loopinterface),

src/Factory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ final class Factory
1111
* Creates a new event loop instance
1212
*
1313
* ```php
14+
* // deprecated
1415
* $loop = React\EventLoop\Factory::create();
16+
*
17+
* // new
18+
* $loop = React\EventLoop\Loop::get();
1519
* ```
1620
*
1721
* This method always returns an instance implementing `LoopInterface`,

0 commit comments

Comments
 (0)