@@ -8,7 +8,7 @@ Event loop abstraction layer that libraries can use for evented I/O.
88In order for async based libraries to be interoperable, they need to use the
99same event loop. This component provides a common ` LoopInterface ` that any
1010library 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.
1212
1313> The master branch contains the code for the upcoming 0.5 release.
1414 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
2626 * [ ExtLibeventLoop] ( #extlibeventloop )
2727 * [ ExtLibevLoop] ( #extlibevloop )
2828 * [ LoopInterface] ( #loopinterface )
29+ * [ run()] ( #run )
30+ * [ stop()] ( #stop )
2931 * [ addTimer()] ( #addtimer )
3032 * [ addPeriodicTimer()] ( #addperiodictimer )
3133 * [ cancelTimer()] ( #canceltimer )
@@ -100,7 +102,7 @@ $loop->run();
100102```
101103
1021041 . 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
104106 picks the best available [ loop implementation] ( #loop-implementations ) .
1051072 . The loop instance is used directly or passed to library and application code.
106108 In this example, a periodic timer is registered with the event loop which
@@ -109,7 +111,7 @@ $loop->run();
109111 is created by using ReactPHP's
110112 [ stream component] ( https://github.com/reactphp/stream ) for demonstration
111113 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.
113115
114116### Factory
115117
@@ -237,6 +239,55 @@ to happen any time soon.
237239
238240### LoopInterface
239241
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+
240291#### addTimer()
241292
242293The ` addTimer(float $interval, callable $callback): TimerInterface ` method can be used to
0 commit comments