diff --git a/lib/functions.php b/lib/functions.php index fe11841..2d85aa4 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -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); }); }; diff --git a/test/MapTest.php b/test/MapTest.php index 49b67aa..f5c2035 100644 --- a/test/MapTest.php +++ b/test/MapTest.php @@ -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)); + } + } }