Skip to content

Commit 81d17c1

Browse files
authored
Merge pull request #231 from clue-labs/deprecated-factory
Improve documentation regarding deprecated Factory
2 parents a499b82 + 86b5f82 commit 81d17c1

File tree

3 files changed

+60
-38
lines changed

3 files changed

+60
-38
lines changed

README.md

+48-34
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ single [`run()`](#run) call that is controlled by the user.
1313

1414
* [Quickstart example](#quickstart-example)
1515
* [Usage](#usage)
16-
* [Loop](#loop)
17-
* [Loop methods](#loop-methods)
18-
* [get()](#get)
19-
* [Factory](#factory)
20-
* [create()](#create)
21-
* [Loop implementations](#loop-implementations)
22-
* [StreamSelectLoop](#streamselectloop)
23-
* [ExtEventLoop](#exteventloop)
24-
* [ExtLibeventLoop](#extlibeventloop)
25-
* [ExtLibevLoop](#extlibevloop)
26-
* [ExtEvLoop](#extevloop)
27-
* [ExtUvLoop](#extuvloop)
28-
* [LoopInterface](#loopinterface)
29-
* [run()](#run)
30-
* [stop()](#stop)
31-
* [addTimer()](#addtimer)
32-
* [addPeriodicTimer()](#addperiodictimer)
33-
* [cancelTimer()](#canceltimer)
34-
* [futureTick()](#futuretick)
35-
* [addSignal()](#addsignal)
36-
* [removeSignal()](#removesignal)
37-
* [addReadStream()](#addreadstream)
38-
* [addWriteStream()](#addwritestream)
39-
* [removeReadStream()](#removereadstream)
40-
* [removeWriteStream()](#removewritestream)
16+
* [Loop](#loop)
17+
* [Loop methods](#loop-methods)
18+
* [get()](#get)
19+
* [~~Factory~~](#factory)
20+
* [~~create()~~](#create)
21+
* [Loop implementations](#loop-implementations)
22+
* [StreamSelectLoop](#streamselectloop)
23+
* [ExtEventLoop](#exteventloop)
24+
* [ExtLibeventLoop](#extlibeventloop)
25+
* [ExtLibevLoop](#extlibevloop)
26+
* [ExtEvLoop](#extevloop)
27+
* [ExtUvLoop](#extuvloop)
28+
* [LoopInterface](#loopinterface)
29+
* [run()](#run)
30+
* [stop()](#stop)
31+
* [addTimer()](#addtimer)
32+
* [addPeriodicTimer()](#addperiodictimer)
33+
* [cancelTimer()](#canceltimer)
34+
* [futureTick()](#futuretick)
35+
* [addSignal()](#addsignal)
36+
* [removeSignal()](#removesignal)
37+
* [addReadStream()](#addreadstream)
38+
* [addWriteStream()](#addwritestream)
39+
* [removeReadStream()](#removereadstream)
40+
* [removeWriteStream()](#removewritestream)
4141
* [Install](#install)
4242
* [Tests](#tests)
4343
* [License](#license)
@@ -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) {
@@ -262,18 +268,26 @@ Loop::run();
262268

263269
See [`LoopInterface`](#loopinterface) for more details about available methods.
264270

265-
### Factory
271+
### ~~Factory~~
272+
273+
> Deprecated since v1.2.0, see [`Loop` class](#loop) instead.
266274
267-
The `Factory` class exists as a convenient way to pick the best available
275+
The deprecated `Factory` class exists as a convenient way to pick the best available
268276
[event loop implementation](#loop-implementations).
269277

270-
#### create()
278+
#### ~~create()~~
271279

272-
The `create(): LoopInterface` method can be used to create a new event loop
273-
instance:
280+
> Deprecated since v1.2.0, see [`Loop::get()`](#get) instead.
281+
282+
The deprecated `create(): LoopInterface` method can be used to
283+
create a new event loop instance:
274284

275285
```php
286+
// deprecated
276287
$loop = React\EventLoop\Factory::create();
288+
289+
// new
290+
$loop = React\EventLoop\Loop::get();
277291
```
278292

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

examples/02-periodic.php

+1-1
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) {

src/Factory.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,31 @@
33
namespace React\EventLoop;
44

55
/**
6-
* The `Factory` class exists as a convenient way to pick the best available event loop implementation.
6+
* [Deprecated] The `Factory` class exists as a convenient way to pick the best available event loop implementation.
7+
*
8+
* @deprecated 1.2.0 See Loop instead.
9+
* @see Loop
710
*/
811
final class Factory
912
{
1013
/**
11-
* Creates a new event loop instance
14+
* [Deprecated] Creates a new event loop instance
1215
*
1316
* ```php
17+
* // deprecated
1418
* $loop = React\EventLoop\Factory::create();
19+
*
20+
* // new
21+
* $loop = React\EventLoop\Loop::get();
1522
* ```
1623
*
1724
* This method always returns an instance implementing `LoopInterface`,
1825
* the actual event loop implementation is an implementation detail.
1926
*
2027
* This method should usually only be called once at the beginning of the program.
2128
*
22-
* @deprecated Use Loop::get instead
29+
* @deprecated 1.2.0 See Loop::get() instead.
30+
* @see Loop::get()
2331
*
2432
* @return LoopInterface
2533
*/

0 commit comments

Comments
 (0)