@@ -8,7 +8,7 @@ Event loop abstraction layer that libraries can use for evented I/O.
8
8
In order for async based libraries to be interoperable, they need to use the
9
9
same event loop. This component provides a common ` LoopInterface ` that any
10
10
library can target. This allows them to be used in the same loop, with one
11
- single ` run() ` call that is controlled by the user.
11
+ single [ ` run() ` ] ( #run ) call that is controlled by the user.
12
12
13
13
> The master branch contains the code for the upcoming 0.5 release.
14
14
For the code of the current stable 0.4.x release, checkout the
@@ -26,6 +26,8 @@ For the code of the current stable 0.4.x release, checkout the
26
26
* [ ExtLibeventLoop] ( #extlibeventloop )
27
27
* [ ExtLibevLoop] ( #extlibevloop )
28
28
* [ LoopInterface] ( #loopinterface )
29
+ * [ run()] ( #run )
30
+ * [ stop()] ( #stop )
29
31
* [ addTimer()] ( #addtimer )
30
32
* [ addPeriodicTimer()] ( #addperiodictimer )
31
33
* [ cancelTimer()] ( #canceltimer )
@@ -100,7 +102,7 @@ $loop->run();
100
102
```
101
103
102
104
1 . The loop instance is created at the beginning of the program. A convenience
103
- factory ` React\EventLoop\Factory::create() ` is provided by this library which
105
+ factory [ ` React\EventLoop\Factory::create() ` ] ( #create ) is provided by this library which
104
106
picks the best available [ loop implementation] ( #loop-implementations ) .
105
107
2 . The loop instance is used directly or passed to library and application code.
106
108
In this example, a periodic timer is registered with the event loop which
@@ -109,7 +111,7 @@ $loop->run();
109
111
is created by using ReactPHP's
110
112
[ stream component] ( https://github.com/reactphp/stream ) for demonstration
111
113
purposes.
112
- 3 . The loop is run with a single ` $loop->run() ` call at the end of the program.
114
+ 3 . The loop is run with a single [ ` $loop->run() ` ] ( #run ) call at the end of the program.
113
115
114
116
### Factory
115
117
@@ -237,6 +239,55 @@ to happen any time soon.
237
239
238
240
### LoopInterface
239
241
242
+ #### run()
243
+
244
+ The ` run(): void ` method can be used to
245
+ run the event loop until there are no more tasks to perform.
246
+
247
+ For many applications, this method is the only directly visible
248
+ invocation on the event loop.
249
+ As a rule of thumb, it is usally recommended to attach everything to the
250
+ same loop instance and then run the loop once at the bottom end of the
251
+ application.
252
+
253
+ ``` php
254
+ $loop->run();
255
+ ```
256
+
257
+ This method will keep the loop running until there are no more tasks
258
+ to perform. In other words: This method will block until the last
259
+ timer, stream and/or signal has been removed.
260
+
261
+ Likewise, it is imperative to ensure the application actually invokes
262
+ this method once. Adding listeners to the loop and missing to actually
263
+ run it will result in the application exiting without actually waiting
264
+ for any of the attached listeners.
265
+
266
+ This method MUST NOT be called while the loop is already running.
267
+ This method MAY be called more than once after it has explicity been
268
+ [ ` stop() ` ped] ( #stop ) or after it automatically stopped because it
269
+ previously did no longer have anything to do.
270
+
271
+ #### stop()
272
+
273
+ The ` stop(): void ` method can be used to
274
+ instruct a running event loop to stop.
275
+
276
+ This method is considered advanced usage and should be used with care.
277
+ As a rule of thumb, it is usually recommended to let the loop stop
278
+ only automatically when it no longer has anything to do.
279
+
280
+ This method can be used to explicitly instruct the event loop to stop:
281
+
282
+ ``` php
283
+ $loop->addTimer(3.0, function () use ($loop) {
284
+ $loop->stop();
285
+ });
286
+ ```
287
+
288
+ Calling this method on a loop instance that is not currently running or
289
+ on a loop instance that has already been stopped has no effect.
290
+
240
291
#### addTimer()
241
292
242
293
The ` addTimer(float $interval, callable $callback): TimerInterface ` method can be used to
0 commit comments