1
0
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:
Daniel Lowrey 2014-12-04 13:34:42 -05:00
parent 8dce4b291c
commit a8fe6e2e39
2 changed files with 55 additions and 1 deletions

View File

@ -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
View 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);
});
}
}