@@ -13,31 +13,31 @@ single [`run()`](#run) call that is controlled by the user.
13
13
14
14
* [ Quickstart example] ( #quickstart-example )
15
15
* [ 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 )
41
41
* [ Install] ( #install )
42
42
* [ Tests] ( #tests )
43
43
* [ License] ( #license )
@@ -48,8 +48,12 @@ single [`run()`](#run) call that is controlled by the user.
48
48
Here is an async HTTP server built with just the event loop.
49
49
50
50
``` php
51
+ <?php
52
+
51
53
use React\EventLoop\Loop;
52
54
55
+ require __DIR__ . '/vendor/autoload.php';
56
+
53
57
$server = stream_socket_server('tcp://127.0.0.1:8080');
54
58
stream_set_blocking($server, false);
55
59
@@ -81,14 +85,15 @@ See also the [examples](examples).
81
85
## Usage
82
86
83
87
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:
85
89
86
90
``` php
87
91
use React\EventLoop\Loop;
88
92
89
93
$timer = Loop::addPeriodicTimer(0.1, function () {
90
- echo " Tick" . PHP_EOL;
94
+ echo ' Tick' . PHP_EOL;
91
95
});
96
+
92
97
Loop::addTimer(1.0, function () use ($timer) {
93
98
Loop::cancelTimer($timer);
94
99
echo 'Done' . PHP_EOL;
@@ -105,8 +110,9 @@ program like this:
105
110
$loop = React\EventLoop\Loop::get(); // or deprecated React\EventLoop\Factory::create();
106
111
107
112
$timer = $loop->addPeriodicTimer(0.1, function () {
108
- echo " Tick" . PHP_EOL;
113
+ echo ' Tick' . PHP_EOL;
109
114
});
115
+
110
116
$loop->addTimer(1.0, function () use ($loop, $timer) {
111
117
$loop->cancelTimer($timer);
112
118
echo 'Done' . PHP_EOL;
@@ -163,7 +169,7 @@ like this:
163
169
use React\EventLoop\Loop;
164
170
165
171
$timer = Loop::addPeriodicTimer(0.1, function () {
166
- echo 'tick! ' . PHP_EOL;
172
+ echo 'Tick ' . PHP_EOL;
167
173
});
168
174
169
175
Loop::addTimer(1.0, function () use ($timer) {
@@ -262,18 +268,26 @@ Loop::run();
262
268
263
269
See [ ` LoopInterface ` ] ( #loopinterface ) for more details about available methods.
264
270
265
- ### Factory
271
+ ### ~~ Factory~~
272
+
273
+ > Deprecated since v1.2.0, see [ ` Loop ` class] ( #loop ) instead.
266
274
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
268
276
[ event loop implementation] ( #loop-implementations ) .
269
277
270
- #### create()
278
+ #### ~~ create()~~
271
279
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:
274
284
275
285
``` php
286
+ // deprecated
276
287
$loop = React\EventLoop\Factory::create();
288
+
289
+ // new
290
+ $loop = React\EventLoop\Loop::get();
277
291
```
278
292
279
293
This method always returns an instance implementing [ ` LoopInterface ` ] ( #loopinterface ) ,
0 commit comments