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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function blockingExample()
$request2 = $browser->get('http://www.google.co.uk/');

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

return $fasterResponse->getBody();
}
Expand All @@ -73,9 +73,9 @@ The `wait($seconds)` method can be used to wait/sleep for $time seconds.

The `awaitOne(PromiseInterface $promise)` method can be used to block waiting for the given $promise to resolve.

#### awaitRace()
#### awaitAny()

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

#### awaitAll()

Expand Down
2 changes: 1 addition & 1 deletion src/Blocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function ($error) use (&$exception, &$wait, $loop) {
* @return mixed returns whatever the first promise resolves to
* @throws Exception if ALL promises are rejected
*/
public function awaitRace(array $promises)
public function awaitAny(array $promises)
{
$wait = count($promises);
$value = null;
Expand Down
20 changes: 10 additions & 10 deletions tests/BlockerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ public function testAwaitOneInterrupted()
/**
* @expectedException UnderflowException
*/
public function testAwaitRaceEmpty()
public function testAwaitAnyEmpty()
{
$this->block->awaitRace(array());
$this->block->awaitAny(array());
}

public function testAwaitRaceFirstResolved()
public function testAwaitAnyFirstResolved()
{
$all = array(
$this->createPromiseRejected(1),
$this->createPromiseResolved(2, 0.01),
$this->createPromiseResolved(3, 0.02)
);

$this->assertEquals(2, $this->block->awaitRace($all));
$this->assertEquals(2, $this->block->awaitAny($all));
}

public function testAwaitRaceFirstResolvedConcurrently()
public function testAwaitAnyFirstResolvedConcurrently()
{
$d1 = new Deferred();
$d2 = new Deferred();
Expand All @@ -83,26 +83,26 @@ public function testAwaitRaceFirstResolvedConcurrently()
$d3->promise()
);

$this->assertEquals(2, $this->block->awaitRace($all));
$this->assertEquals(2, $this->block->awaitAny($all));
}

public function testAwaitRaceAllRejected()
public function testAwaitAnyAllRejected()
{
$all = array(
$this->createPromiseRejected(1),
$this->createPromiseRejected(2)
);

$this->setExpectedException('UnderflowException');
$this->block->awaitRace($all);
$this->block->awaitAny($all);
}

public function testAwaitRaceInterrupted()
public function testAwaitAnyInterrupted()
{
$promise = $this->createPromiseResolved(2, 0.02);
$this->createTimerInterrupt(0.01);

$this->assertEquals(2, $this->block->awaitRace(array($promise)));
$this->assertEquals(2, $this->block->awaitAny(array($promise)));
}

public function testAwaitAllEmpty()
Expand Down