@@ -35,7 +35,6 @@ function blockingExample()
3535{
3636 // use a unique event loop instance for all parallel operations
3737 $loop = React\EventLoop\Factory::create();
38- $blocker = new Blocker($loop);
3938
4039 // this example uses an HTTP client
4140 // this could be pretty much everything that binds to an event loop
@@ -46,40 +45,56 @@ function blockingExample()
4645 $request2 = $browser->get('http://www.google.co.uk/');
4746
4847 // keep the loop running (i.e. block) until the first response arrives
49- $fasterResponse = $blocker-> awaitAny(array($request1, $request2));
48+ $fasterResponse = Block\ awaitAny(array($request1, $request2), $loop );
5049
5150 return $fasterResponse->getBody();
5251}
5352```
5453
5554## Usage
5655
57- ### Blocker
56+ This lightweight library consists only of a few simple functions.
57+ All functions reside under the ` Clue\React\Block ` namespace.
5858
59- The ` Blocker ` is responsible for orchestrating the
59+ The below examples assume you use an import statement similar to this:
60+
61+ ``` php
62+ use Clue\React\Block;
63+
64+ Block\await(…);
65+ ```
66+
67+ Alternatively, you can also refer to them with their fully-qualified name:
68+
69+ ``` php
70+ \Clue\React\Block\await(…);
71+ ```
72+
73+ ### EventLoop
74+
75+ Each function is responsible for orchestrating the
6076[ ` EventLoop ` ] ( https://github.com/reactphp/event-loop#usage )
6177in order to make it run (block) until your conditions are fulfilled.
6278
6379``` php
6480$loop = React\EventLoop\Factory::create();
65- $blocker = new Blocker($loop);
6681```
6782
6883#### sleep()
6984
70- The ` sleep($seconds) ` method can be used to wait/sleep for $time seconds.
85+ The ` sleep($seconds, LoopInterface $loop ) ` method can be used to wait/sleep for $time seconds.
7186
7287#### await()
7388
74- The ` await(PromiseInterface $promise) ` method can be used to block waiting for the given $promise to resolve.
89+ The ` await(PromiseInterface $promise, LoopInterface $loop ) ` method can be used to block waiting for the given $promise to resolve.
7590
7691#### awaitAny()
7792
78- The ` awaitAny(array $promises) ` method can be used to wait for ANY of the given promises to resolve.
93+ The ` awaitAny(array $promises, LoopInterface $loop ) ` method can be used to wait for ANY of the given promises to resolve.
7994
8095#### awaitAll()
8196
82- The ` awaitAll(array $promises) ` method can be used to wait for ALL of the given promises to resolve.
97+ The ` awaitAll(array $promises, LoopInterface $loop ) ` method can be used to wait for ALL of the given promises to resolve.
8398
8499## Install
85100
0 commit comments