Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function blockingExample()
{
// use a unique event loop instance for all parallel operations
$loop = React\EventLoop\Factory::create();
$blocker = new Blocker($loop);

// this example uses an HTTP client
// this could be pretty much everything that binds to an event loop
Expand All @@ -46,40 +45,56 @@ function blockingExample()
$request2 = $browser->get('http://www.google.co.uk/');

// keep the loop running (i.e. block) until the first response arrives
$fasterResponse = $blocker->awaitAny(array($request1, $request2));
$fasterResponse = Block\awaitAny(array($request1, $request2), $loop);

return $fasterResponse->getBody();
}
```

## Usage

### Blocker
This lightweight library consists only of a few simple functions.
All functions reside under the `Clue\React\Block` namespace.

The `Blocker` is responsible for orchestrating the
The below examples assume you use an import statement similar to this:

```php
use Clue\React\Block;

Block\await(…);
```

Alternatively, you can also refer to them with their fully-qualified name:

```php
\Clue\React\Block\await(…);
```

### EventLoop

Each function is responsible for orchestrating the
[`EventLoop`](https://github.com/reactphp/event-loop#usage)
in order to make it run (block) until your conditions are fulfilled.

```php
$loop = React\EventLoop\Factory::create();
$blocker = new Blocker($loop);
```

#### sleep()

The `sleep($seconds)` method can be used to wait/sleep for $time seconds.
The `sleep($seconds, LoopInterface $loop)` method can be used to wait/sleep for $time seconds.

#### await()

The `await(PromiseInterface $promise)` method can be used to block waiting for the given $promise to resolve.
The `await(PromiseInterface $promise, LoopInterface $loop)` method can be used to block waiting for the given $promise to resolve.

#### awaitAny()

The `awaitAny(array $promises)` method can be used to wait for ANY of the given promises to resolve.
The `awaitAny(array $promises, LoopInterface $loop)` method can be used to wait for ANY of the given promises to resolve.

#### awaitAll()

The `awaitAll(array $promises)` method can be used to wait for ALL of the given promises to resolve.
The `awaitAll(array $promises, LoopInterface $loop)` method can be used to wait for ALL of the given promises to resolve.

## Install

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
}
],
"autoload": {
"psr-4": { "Clue\\React\\Block\\": "src/" }
"files": [ "src/functions.php" ]
},
"require": {
"php": ">=5.3",
"react/event-loop": "0.4.*|0.3.*",
"react/promise": "~2.0|~1.0"
"react/promise": "~2.0|~1.1"
}
}
205 changes: 0 additions & 205 deletions src/Blocker.php

This file was deleted.

Loading