@@ -13,30 +13,30 @@ 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
- * [ 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 )
40
40
* [ Install] ( #install )
41
41
* [ Tests] ( #tests )
42
42
* [ License] ( #license )
@@ -83,34 +83,29 @@ Typical applications use a single event loop which is created at the beginning
83
83
and run at the end of the program.
84
84
85
85
``` php
86
- // [1]
87
- $loop = React\EventLoop\Factory::create();
86
+ $loop = React\EventLoop\Loop::get(); // or deprecated React\EventLoop\Factory::create();
88
87
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;
92
94
});
93
95
94
- $stream = new React\Stream\ReadableResourceStream(
95
- fopen('file.txt', 'r'),
96
- $loop
97
- );
98
-
99
- // [3]
100
96
$loop->run();
101
97
```
102
98
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.
114
109
115
110
### Loop
116
111
@@ -139,13 +134,17 @@ Loop::get()->run();
139
134
The ` Factory ` class exists as a convenient way to pick the best available
140
135
[ event loop implementation] ( #loop-implementations ) .
141
136
142
- #### create()
137
+ #### ~~ create()~~
143
138
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:
146
141
147
142
``` php
143
+ // deprecated
148
144
$loop = React\EventLoop\Factory::create();
145
+
146
+ // new
147
+ $loop = React\EventLoop\Loop::get();
149
148
```
150
149
151
150
This method always returns an instance implementing [ ` LoopInterface ` ] ( #loopinterface ) ,
0 commit comments