mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
Fix combinator function derps
This commit is contained in:
parent
8dce4b291c
commit
a8fe6e2e39
@ -261,6 +261,10 @@ function all(array $promises) {
|
||||
});
|
||||
}
|
||||
|
||||
if (empty($remaining)) {
|
||||
$promisor->succeed($results);
|
||||
}
|
||||
|
||||
// We can return $promisor directly because the Future Promisor implementation
|
||||
// also implements Promise for convenience
|
||||
return $promisor;
|
||||
@ -289,7 +293,8 @@ function some(array $promises) {
|
||||
));
|
||||
}
|
||||
|
||||
$results = $errors = [];
|
||||
$errors = [];
|
||||
$results = [];
|
||||
$remaining = count($promises);
|
||||
$promisor = new Future;
|
||||
|
||||
@ -319,6 +324,10 @@ function some(array $promises) {
|
||||
});
|
||||
}
|
||||
|
||||
if (empty($remaining)) {
|
||||
$promisor->succeed([$errors, $results]);
|
||||
}
|
||||
|
||||
// We can return $promisor directly because the Future Promisor implementation
|
||||
// also implements Promise for convenience
|
||||
return $promisor;
|
||||
@ -363,6 +372,10 @@ function any(array $promises) {
|
||||
});
|
||||
}
|
||||
|
||||
if (empty($remaining)) {
|
||||
$promisor->succeed([$errors, $results]);
|
||||
}
|
||||
|
||||
// We can return $promisor directly because the Future Promisor implementation
|
||||
// also implements Promise for convenience
|
||||
return $promisor;
|
||||
|
41
test/FunctionsTest.php
Normal file
41
test/FunctionsTest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
class FunctionsTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testAllResolutionWhenNoPromiseInstancesCombined() {
|
||||
$promises = [null, 1, 2, true];
|
||||
\Amp\all($promises)->when(function($e, $r) {
|
||||
list($a, $b, $c, $d) = $r;
|
||||
$this->assertNull($a);
|
||||
$this->assertSame(1, $b);
|
||||
$this->assertSame(2, $c);
|
||||
$this->assertSame(true, $d);
|
||||
});
|
||||
}
|
||||
|
||||
public function testSomeResolutionWhenNoPromiseInstancesCombined() {
|
||||
$promises = [null, 1, 2, true];
|
||||
\Amp\some($promises)->when(function($e, $r) {
|
||||
list($errors, $results) = $r;
|
||||
list($a, $b, $c, $d) = $results;
|
||||
$this->assertNull($a);
|
||||
$this->assertSame(1, $b);
|
||||
$this->assertSame(2, $c);
|
||||
$this->assertSame(true, $d);
|
||||
});
|
||||
}
|
||||
|
||||
public function testAnyResolutionWhenNoPromiseInstancesCombined() {
|
||||
$promises = [null, 1, 2, true];
|
||||
\Amp\any($promises)->when(function($e, $r) {
|
||||
list($errors, $results) = $r;
|
||||
list($a, $b, $c, $d) = $results;
|
||||
$this->assertNull($a);
|
||||
$this->assertSame(1, $b);
|
||||
$this->assertSame(2, $c);
|
||||
$this->assertSame(true, $d);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user