Skip to content

Commit 7dafc25

Browse files
committed
Simplifies logging logic
1 parent 050ea6b commit 7dafc25

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/Async.php

+22-22
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace LogicalSteps\Async;
44

55

6+
use Amp\Loop\Driver;
67
use Closure;
8+
use Exception;
79
use Generator;
810
use Psr\Log\LoggerInterface;
911
use React\EventLoop\LoopInterface;
10-
use Amp\Loop\Driver;
1112
use React\Promise\Promise;
1213
use React\Promise\PromiseInterface;
1314
use ReflectionException;
@@ -18,6 +19,7 @@
1819
use ReflectionObject;
1920
use Throwable;
2021
use TypeError;
22+
use UnexpectedValueException;
2123

2224
use function GuzzleHttp\Promise\all as guzzleAll;
2325

@@ -45,23 +47,23 @@
4547
*/
4648
class Async
4749
{
48-
const PROMISE_REACT = 'React\Promise\PromiseInterface';
49-
const PROMISE_AMP = 'Amp\Promise';
50-
const PROMISE_GUZZLE = 'GuzzleHttp\Promise\PromiseInterface';
51-
const PROMISE_HTTP = 'Http\Promise\Promise';
50+
public const PROMISE_REACT = 'React\Promise\PromiseInterface';
51+
public const PROMISE_AMP = 'Amp\Promise';
52+
public const PROMISE_GUZZLE = 'GuzzleHttp\Promise\PromiseInterface';
53+
public const PROMISE_HTTP = 'Http\Promise\Promise';
5254

5355
/** @var string action to return a promise instead of awaiting the response of the process. */
54-
const promise = 'promise';
56+
public const promise = 'promise';
5557
/** @var string action to run current process side by side with the remainder of the process. */
56-
const parallel = 'parallel';
58+
public const parallel = 'parallel';
5759
/** @var string action to await for all parallel processes previously to finish. */
58-
const all = 'all';
60+
public const all = 'all';
5961
/** @var string action to await for current processes to finish. this is the default action. */
60-
const await = 'await';
62+
public const await = 'await';
6163
/** @var string action to run current process after finished executing the function. */
62-
const later = 'later';
64+
public const later = 'later';
6365

64-
const ACTIONS = [self::await, self::parallel, self::all, self::promise, self::later];
66+
public const ACTIONS = [self::await, self::parallel, self::all, self::promise, self::later];
6567

6668
public static $knownPromises = [
6769
self::PROMISE_REACT,
@@ -288,8 +290,8 @@ protected function _wait($process)
288290
$this->logger->info('end');
289291
}
290292
if ($isRejected) {
291-
if (!$exception instanceof \Exception) {
292-
$exception = new \UnexpectedValueException(
293+
if (!$exception instanceof Exception) {
294+
$exception = new UnexpectedValueException(
293295
'process failed with ' . (is_object($exception) ? get_class($exception) : gettype($exception))
294296
);
295297
}
@@ -434,7 +436,7 @@ function ($error = null, $results = null) {
434436
/**
435437
* Handle known promise interfaces
436438
*
437-
* @param \React\Promise\PromiseInterface|\GuzzleHttp\Promise\PromiseInterface|\Amp\Promise|\Http\Promise\Promise $knownPromise
439+
* @param PromiseInterface|\GuzzleHttp\Promise\PromiseInterface|\Amp\Promise|\Http\Promise\Promise $knownPromise
438440
* @param string $interface
439441
* @param callable $callback
440442
* @param int $depth
@@ -478,7 +480,7 @@ function ($error = null, $result = null) use ($resolver, $rejector) {
478480
);
479481
break;
480482
}
481-
} catch (\Exception $e) {
483+
} catch (Exception $e) {
482484
$rejector($e);
483485
}
484486
}
@@ -512,14 +514,12 @@ private function logCallback(callable $callable, array $parameters, int $depth =
512514
} else {
513515
$name .= '::' . $callable[1];
514516
}
517+
} elseif (is_string($callable)) {
518+
$name = $callable;
519+
} elseif ($callable instanceof Closure) {
520+
$name = '$closure';
515521
} else {
516-
if (is_string($callable)) {
517-
$name = $callable;
518-
} elseif ($callable instanceof Closure) {
519-
$name = '$closure';
520-
} else {
521-
$name = '$callable';
522-
}
522+
$name = '$callable';
523523
}
524524
$this->logger->info(
525525
sprintf("%s %s%s", $this->action(), $name, $this->format($parameters)),

0 commit comments

Comments
 (0)