aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/event/lib/Promise
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-05-07 23:35:02 +0200
committerMario <mario@mariovavti.com>2020-05-07 23:35:02 +0200
commitfae70bf0a7f1b566d25e30064f60d58ab150951a (patch)
tree1714511edb85ed0e28034ed9371d5fc515504fd6 /vendor/sabre/event/lib/Promise
parentffd2faf8a09a870e8dbecb3ad168e0a9b25941d3 (diff)
downloadvolse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.tar.gz
volse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.tar.bz2
volse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.zip
Revert "composer updates"
This reverts commit dbfe748d274f6843fc91a3071df7be45c4ab5b00
Diffstat (limited to 'vendor/sabre/event/lib/Promise')
-rw-r--r--vendor/sabre/event/lib/Promise/functions.php53
1 files changed, 30 insertions, 23 deletions
diff --git a/vendor/sabre/event/lib/Promise/functions.php b/vendor/sabre/event/lib/Promise/functions.php
index 986fe2b00..275492cbc 100644
--- a/vendor/sabre/event/lib/Promise/functions.php
+++ b/vendor/sabre/event/lib/Promise/functions.php
@@ -1,6 +1,4 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event\Promise;
@@ -16,6 +14,7 @@ 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.
@@ -25,17 +24,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 immediately
+ * If any of the given Promises fails, the returned promise will immidiately
* 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;
}
@@ -43,23 +42,25 @@ 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);
}
);
+
}
});
+
}
/**
@@ -71,20 +72,22 @@ 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;
}
@@ -92,10 +95,14 @@ function race(array $promises): Promise
$fail($reason);
}
);
+
}
+
});
+
}
+
/**
* Returns a Promise that resolves with the given value.
*
@@ -104,25 +111,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;
+
}