1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 05:11:42 +01:00

Ensure correct argument order in multi-argument lift

This commit is contained in:
Aaron Piotrowski 2017-02-09 22:34:24 -06:00
parent 3861c6b5da
commit b72e504eab
2 changed files with 24 additions and 1 deletions

View File

@ -243,6 +243,7 @@ function lift(callable $worker): callable {
}
return pipe(all($args), function (array $args) use ($worker) {
\ksort($args); // Needed to ensure correct argument order.
return $worker(...$args);
});
};

View File

@ -3,7 +3,7 @@
namespace Amp\Test;
use Amp;
use Amp\{ Deferred, Failure, Success };
use Amp\{ Deferred, Failure, Pause, Success };
use AsyncInterop\{ Loop, Promise };
class MapTest extends \PHPUnit_Framework_TestCase {
@ -151,4 +151,26 @@ class MapTest extends \PHPUnit_Framework_TestCase {
$this->assertSame(4, Amp\wait($promise));
}
}
/**
* @depends testMultipleArrays
*/
public function testMultipleArrayArgumentOrder() {
$promises1 = [new Pause(10, 1), new Pause(20, 1), new Pause(30, 1)];;
$promises2 = [new Pause(30, 3), new Pause(20, 3), new Pause(10, 3)];;
$count = 0;
$callback = function ($value1, $value2) use (&$count) {
++$count;
$this->assertSame(1, $value1);
$this->assertSame(3, $value2);
return $value1 + $value2;
};
$result = Amp\map($callback, $promises1, $promises2);
foreach ($result as $promise) {
$this->assertSame(4, Amp\wait($promise));
}
}
}