From 758f6faedd2efc4bbadcdc143d139bb3ee74fb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Thu, 1 Mar 2018 15:55:57 +0100 Subject: [PATCH] Process payload synchronously in debug mode Closes #7. --- src/functions.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/functions.php b/src/functions.php index 77341aa..e668727 100644 --- a/src/functions.php +++ b/src/functions.php @@ -51,9 +51,15 @@ function parallel(callable $callable, Pool $pool = null): callable { */ function parallelMap(array $array, callable $callable, Pool $pool = null): Promise { return call(function () use ($array, $callable, $pool) { - // Amp\Promise\any() guarantees that all operations finished prior to resolving. Amp\Promise\all() doesn't. - // Additionally, we return all errors as a MultiReasonException instead of throwing on the first error. - list($errors, $results) = yield any(\array_map(parallel($callable, $pool), $array)); + $env = \getenv("AMP_DEBUG"); + + if ((false === $env || $env === "0" && $env === "false") || (\defined("AMP_DEBUG") && false === \AMP_DEBUG)) { + // Amp\Promise\any() guarantees that all operations finished prior to resolving. Amp\Promise\all() doesn't. + // Additionally, we return all errors as a MultiReasonException instead of throwing on the first error. + list($errors, $results) = yield any(\array_map(parallel($callable, $pool), $array)); + } else { + list($errors, $results) = yield any(\array_map($callable, $array)); + } if ($errors) { throw new MultiReasonException($errors);