diff options
author | Mario <mario@mariovavti.com> | 2020-05-07 15:22:25 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-05-07 15:22:25 +0000 |
commit | dbfe748d274f6843fc91a3071df7be45c4ab5b00 (patch) | |
tree | 3b59194620f319b16a88dcc2aa5bacbea1c3d188 /vendor/sabre/event/lib/Promise/functions.php | |
parent | 4ee809bed6ea023ad9e2888eedd65e083d4c1e3e (diff) | |
download | volse-hubzilla-dbfe748d274f6843fc91a3071df7be45c4ab5b00.tar.gz volse-hubzilla-dbfe748d274f6843fc91a3071df7be45c4ab5b00.tar.bz2 volse-hubzilla-dbfe748d274f6843fc91a3071df7be45c4ab5b00.zip |
composer updates
Diffstat (limited to 'vendor/sabre/event/lib/Promise/functions.php')
-rw-r--r-- | vendor/sabre/event/lib/Promise/functions.php | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/vendor/sabre/event/lib/Promise/functions.php b/vendor/sabre/event/lib/Promise/functions.php index 275492cbc..986fe2b00 100644 --- a/vendor/sabre/event/lib/Promise/functions.php +++ b/vendor/sabre/event/lib/Promise/functions.php @@ -1,4 +1,6 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event\Promise; @@ -14,7 +16,6 @@ use Throwable; * @license http://sabre.io/license/ Modified BSD License */ - /** * This function takes an array of Promises, and returns a Promise that * resolves when all of the given arguments have resolved. @@ -24,17 +25,17 @@ use Throwable; * * This array will be in the exact same order as the array of input promises. * - * If any of the given Promises fails, the returned promise will immidiately + * If any of the given Promises fails, the returned promise will immediately * fail with the first Promise that fails, and its reason. * * @param Promise[] $promises */ -function all(array $promises) : Promise { - - return new Promise(function($success, $fail) use ($promises) { - +function all(array $promises): Promise +{ + return new Promise(function ($success, $fail) use ($promises) { if (empty($promises)) { $success([]); + return; } @@ -42,25 +43,23 @@ function all(array $promises) : Promise { $completeResult = []; foreach ($promises as $promiseIndex => $subPromise) { - $subPromise->then( - function($result) use ($promiseIndex, &$completeResult, &$successCount, $success, $promises) { + function ($result) use ($promiseIndex, &$completeResult, &$successCount, $success, $promises) { $completeResult[$promiseIndex] = $result; - $successCount++; + ++$successCount; if ($successCount === count($promises)) { $success($completeResult); } + return $result; } )->otherwise( - function($reason) use ($fail) { + function ($reason) use ($fail) { $fail($reason); } ); - } }); - } /** @@ -72,22 +71,20 @@ function all(array $promises) : Promise { * * @param Promise[] $promises */ -function race(array $promises) : Promise { - - return new Promise(function($success, $fail) use ($promises) { - +function race(array $promises): Promise +{ + return new Promise(function ($success, $fail) use ($promises) { $alreadyDone = false; foreach ($promises as $promise) { - $promise->then( - function($result) use ($success, &$alreadyDone) { + function ($result) use ($success, &$alreadyDone) { if ($alreadyDone) { return; } $alreadyDone = true; $success($result); }, - function($reason) use ($fail, &$alreadyDone) { + function ($reason) use ($fail, &$alreadyDone) { if ($alreadyDone) { return; } @@ -95,14 +92,10 @@ function race(array $promises) : Promise { $fail($reason); } ); - } - }); - } - /** * Returns a Promise that resolves with the given value. * @@ -111,25 +104,25 @@ function race(array $promises) : Promise { * * @param mixed $value */ -function resolve($value) : Promise { - +function resolve($value): Promise +{ if ($value instanceof Promise) { return $value->then(); } else { $promise = new Promise(); $promise->fulfill($value); + return $promise; } - } /** * Returns a Promise that will reject with the given reason. */ -function reject(Throwable $reason) : Promise { - +function reject(Throwable $reason): Promise +{ $promise = new Promise(); $promise->reject($reason); - return $promise; + return $promise; } |