Skip to content

Commit 7170c00

Browse files
committed
Merge pull request #13 from clue-labs/functional
Functional API
2 parents 29f1c00 + 4e49f1e commit 7170c00

11 files changed

+375
-398
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
6177
in 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

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
}
1212
],
1313
"autoload": {
14-
"psr-4": { "Clue\\React\\Block\\": "src/" }
14+
"files": [ "src/functions.php" ]
1515
},
1616
"require": {
1717
"php": ">=5.3",
1818
"react/event-loop": "0.4.*|0.3.*",
19-
"react/promise": "~2.0|~1.0"
19+
"react/promise": "~2.0|~1.1"
2020
}
2121
}

src/Blocker.php

Lines changed: 0 additions & 205 deletions
This file was deleted.

0 commit comments

Comments
 (0)