@@ -82,18 +82,63 @@ $loop = React\EventLoop\Factory::create();
8282
8383The ` sleep($seconds, LoopInterface $loop) ` method can be used to wait/sleep for $time seconds.
8484
85+ ``` php
86+ Block\sleep(1.5, $loop);
87+ ```
88+
89+ Similar to PHP's [ ` sleep() ` ] ( http://php.net/sleep ) function.
90+ Allows for floating point.
91+ Loop can perform other (async) tasks.
92+
8593#### await()
8694
8795The ` await(PromiseInterface $promise, LoopInterface $loop) ` method can be used to block waiting for the given $promise to resolve.
8896
97+ ``` php
98+ $result = Block\await($promise, $loop);
99+ ```
100+
101+ ``` php
102+ try {
103+ $value = Block\await($promise, $loop);
104+ // promise successfully fulfilled with $value
105+ echo 'Result: ' . $value;
106+ } catch (Exeption $exception) {
107+ // promise rejected with $exception
108+ echo 'ERROR: ' . $exception->getMessage();
109+ }
110+ ```
111+
89112#### awaitAny()
90113
91114The ` awaitAny(array $promises, LoopInterface $loop) ` method can be used to wait for ANY of the given promises to resolve.
92115
116+ ``` php
117+ $promises = array(
118+ $promise1,
119+ $promise2
120+ );
121+
122+ $result = Block\awaitAny($promises, $loop);
123+ ```
124+
125+ Once the first promise is resolved, this will try to cancel() all
126+ * remaining promises and return whatever the first promise resolves to.
127+ *
128+ * If ALL promises fail to resolve, this will fail and throw an Exception.
129+
93130#### awaitAll()
94131
95132The ` awaitAll(array $promises, LoopInterface $loop) ` method can be used to wait for ALL of the given promises to resolve.
96133
134+
135+ Once the last promise resolves, this will return an array with whatever
136+ * each promise resolves to. Array keys will be left intact, i.e. they can
137+ * be used to correlate the return array to the promises passed.
138+ *
139+ * If ANY promise fails to resolve, this will try to cancel() all
140+ * remaining promises and throw an Exception.
141+
97142## Install
98143
99144The recommended way to install this library is [ through composer] ( http://getcomposer.org ) . [ New to composer?] ( http://getcomposer.org/doc/00-intro.md )
0 commit comments