| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,91 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+declare(strict_types=1); |
|
| 4 |
+ |
|
| 5 |
+namespace GuzzleHttp\Promise; |
|
| 6 |
+ |
|
| 7 |
+/** |
|
| 8 |
+ * A promise represents the eventual result of an asynchronous operation. |
|
| 9 |
+ * |
|
| 10 |
+ * The primary way of interacting with a promise is through its then method, |
|
| 11 |
+ * which registers callbacks to receive either a promise’s eventual value or |
|
| 12 |
+ * the reason why the promise cannot be fulfilled. |
|
| 13 |
+ * |
|
| 14 |
+ * @see https://promisesaplus.com/ |
|
| 15 |
+ */ |
|
| 16 |
+interface PromiseInterface |
|
| 17 |
+{
|
|
| 18 |
+ public const PENDING = 'pending'; |
|
| 19 |
+ public const FULFILLED = 'fulfilled'; |
|
| 20 |
+ public const REJECTED = 'rejected'; |
|
| 21 |
+ |
|
| 22 |
+ /** |
|
| 23 |
+ * Appends fulfillment and rejection handlers to the promise, and returns |
|
| 24 |
+ * a new promise resolving to the return value of the called handler. |
|
| 25 |
+ * |
|
| 26 |
+ * @param callable $onFulfilled Invoked when the promise fulfills. |
|
| 27 |
+ * @param callable $onRejected Invoked when the promise is rejected. |
|
| 28 |
+ */ |
|
| 29 |
+ public function then( |
|
| 30 |
+ ?callable $onFulfilled = null, |
|
| 31 |
+ ?callable $onRejected = null |
|
| 32 |
+ ): PromiseInterface; |
|
| 33 |
+ |
|
| 34 |
+ /** |
|
| 35 |
+ * Appends a rejection handler callback to the promise, and returns a new |
|
| 36 |
+ * promise resolving to the return value of the callback if it is called, |
|
| 37 |
+ * or to its original fulfillment value if the promise is instead |
|
| 38 |
+ * fulfilled. |
|
| 39 |
+ * |
|
| 40 |
+ * @param callable $onRejected Invoked when the promise is rejected. |
|
| 41 |
+ */ |
|
| 42 |
+ public function otherwise(callable $onRejected): PromiseInterface; |
|
| 43 |
+ |
|
| 44 |
+ /** |
|
| 45 |
+ * Get the state of the promise ("pending", "rejected", or "fulfilled").
|
|
| 46 |
+ * |
|
| 47 |
+ * The three states can be checked against the constants defined on |
|
| 48 |
+ * PromiseInterface: PENDING, FULFILLED, and REJECTED. |
|
| 49 |
+ */ |
|
| 50 |
+ public function getState(): string; |
|
| 51 |
+ |
|
| 52 |
+ /** |
|
| 53 |
+ * Resolve the promise with the given value. |
|
| 54 |
+ * |
|
| 55 |
+ * @param mixed $value |
|
| 56 |
+ * |
|
| 57 |
+ * @throws \RuntimeException if the promise is already resolved. |
|
| 58 |
+ */ |
|
| 59 |
+ public function resolve($value): void; |
|
| 60 |
+ |
|
| 61 |
+ /** |
|
| 62 |
+ * Reject the promise with the given reason. |
|
| 63 |
+ * |
|
| 64 |
+ * @param mixed $reason |
|
| 65 |
+ * |
|
| 66 |
+ * @throws \RuntimeException if the promise is already resolved. |
|
| 67 |
+ */ |
|
| 68 |
+ public function reject($reason): void; |
|
| 69 |
+ |
|
| 70 |
+ /** |
|
| 71 |
+ * Cancels the promise if possible. |
|
| 72 |
+ * |
|
| 73 |
+ * @see https://github.com/promises-aplus/cancellation-spec/issues/7 |
|
| 74 |
+ */ |
|
| 75 |
+ public function cancel(): void; |
|
| 76 |
+ |
|
| 77 |
+ /** |
|
| 78 |
+ * Waits until the promise completes if possible. |
|
| 79 |
+ * |
|
| 80 |
+ * Pass $unwrap as true to unwrap the result of the promise, either |
|
| 81 |
+ * returning the resolved value or throwing the rejected exception. |
|
| 82 |
+ * |
|
| 83 |
+ * If the promise cannot be waited on, then the promise will be rejected. |
|
| 84 |
+ * |
|
| 85 |
+ * @return mixed |
|
| 86 |
+ * |
|
| 87 |
+ * @throws \LogicException if the promise has no wait function or if the |
|
| 88 |
+ * promise does not settle after waiting. |
|
| 89 |
+ */ |
|
| 90 |
+ public function wait(bool $unwrap = true); |
|
| 91 |
+} |
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,97 +0,0 @@ |
| 1 |
-<?php |
|
| 2 |
- |
|
| 3 |
-namespace GuzzleHttp\Promise; |
|
| 4 |
- |
|
| 5 |
-/** |
|
| 6 |
- * A promise represents the eventual result of an asynchronous operation. |
|
| 7 |
- * |
|
| 8 |
- * The primary way of interacting with a promise is through its then method, |
|
| 9 |
- * which registers callbacks to receive either a promise’s eventual value or |
|
| 10 |
- * the reason why the promise cannot be fulfilled. |
|
| 11 |
- * |
|
| 12 |
- * @link https://promisesaplus.com/ |
|
| 13 |
- */ |
|
| 14 |
-interface PromiseInterface |
|
| 15 |
-{
|
|
| 16 |
- const PENDING = 'pending'; |
|
| 17 |
- const FULFILLED = 'fulfilled'; |
|
| 18 |
- const REJECTED = 'rejected'; |
|
| 19 |
- |
|
| 20 |
- /** |
|
| 21 |
- * Appends fulfillment and rejection handlers to the promise, and returns |
|
| 22 |
- * a new promise resolving to the return value of the called handler. |
|
| 23 |
- * |
|
| 24 |
- * @param callable $onFulfilled Invoked when the promise fulfills. |
|
| 25 |
- * @param callable $onRejected Invoked when the promise is rejected. |
|
| 26 |
- * |
|
| 27 |
- * @return PromiseInterface |
|
| 28 |
- */ |
|
| 29 |
- public function then( |
|
| 30 |
- callable $onFulfilled = null, |
|
| 31 |
- callable $onRejected = null |
|
| 32 |
- ); |
|
| 33 |
- |
|
| 34 |
- /** |
|
| 35 |
- * Appends a rejection handler callback to the promise, and returns a new |
|
| 36 |
- * promise resolving to the return value of the callback if it is called, |
|
| 37 |
- * or to its original fulfillment value if the promise is instead |
|
| 38 |
- * fulfilled. |
|
| 39 |
- * |
|
| 40 |
- * @param callable $onRejected Invoked when the promise is rejected. |
|
| 41 |
- * |
|
| 42 |
- * @return PromiseInterface |
|
| 43 |
- */ |
|
| 44 |
- public function otherwise(callable $onRejected); |
|
| 45 |
- |
|
| 46 |
- /** |
|
| 47 |
- * Get the state of the promise ("pending", "rejected", or "fulfilled").
|
|
| 48 |
- * |
|
| 49 |
- * The three states can be checked against the constants defined on |
|
| 50 |
- * PromiseInterface: PENDING, FULFILLED, and REJECTED. |
|
| 51 |
- * |
|
| 52 |
- * @return string |
|
| 53 |
- */ |
|
| 54 |
- public function getState(); |
|
| 55 |
- |
|
| 56 |
- /** |
|
| 57 |
- * Resolve the promise with the given value. |
|
| 58 |
- * |
|
| 59 |
- * @param mixed $value |
|
| 60 |
- * |
|
| 61 |
- * @throws \RuntimeException if the promise is already resolved. |
|
| 62 |
- */ |
|
| 63 |
- public function resolve($value); |
|
| 64 |
- |
|
| 65 |
- /** |
|
| 66 |
- * Reject the promise with the given reason. |
|
| 67 |
- * |
|
| 68 |
- * @param mixed $reason |
|
| 69 |
- * |
|
| 70 |
- * @throws \RuntimeException if the promise is already resolved. |
|
| 71 |
- */ |
|
| 72 |
- public function reject($reason); |
|
| 73 |
- |
|
| 74 |
- /** |
|
| 75 |
- * Cancels the promise if possible. |
|
| 76 |
- * |
|
| 77 |
- * @link https://github.com/promises-aplus/cancellation-spec/issues/7 |
|
| 78 |
- */ |
|
| 79 |
- public function cancel(); |
|
| 80 |
- |
|
| 81 |
- /** |
|
| 82 |
- * Waits until the promise completes if possible. |
|
| 83 |
- * |
|
| 84 |
- * Pass $unwrap as true to unwrap the result of the promise, either |
|
| 85 |
- * returning the resolved value or throwing the rejected exception. |
|
| 86 |
- * |
|
| 87 |
- * If the promise cannot be waited on, then the promise will be rejected. |
|
| 88 |
- * |
|
| 89 |
- * @param bool $unwrap |
|
| 90 |
- * |
|
| 91 |
- * @return mixed |
|
| 92 |
- * |
|
| 93 |
- * @throws \LogicException if the promise has no wait function or if the |
|
| 94 |
- * promise does not settle after waiting. |
|
| 95 |
- */ |
|
| 96 |
- public function wait($unwrap = true); |
|
| 97 |
-} |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,97 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+namespace GuzzleHttp\Promise; |
|
| 4 |
+ |
|
| 5 |
+/** |
|
| 6 |
+ * A promise represents the eventual result of an asynchronous operation. |
|
| 7 |
+ * |
|
| 8 |
+ * The primary way of interacting with a promise is through its then method, |
|
| 9 |
+ * which registers callbacks to receive either a promise’s eventual value or |
|
| 10 |
+ * the reason why the promise cannot be fulfilled. |
|
| 11 |
+ * |
|
| 12 |
+ * @link https://promisesaplus.com/ |
|
| 13 |
+ */ |
|
| 14 |
+interface PromiseInterface |
|
| 15 |
+{
|
|
| 16 |
+ const PENDING = 'pending'; |
|
| 17 |
+ const FULFILLED = 'fulfilled'; |
|
| 18 |
+ const REJECTED = 'rejected'; |
|
| 19 |
+ |
|
| 20 |
+ /** |
|
| 21 |
+ * Appends fulfillment and rejection handlers to the promise, and returns |
|
| 22 |
+ * a new promise resolving to the return value of the called handler. |
|
| 23 |
+ * |
|
| 24 |
+ * @param callable $onFulfilled Invoked when the promise fulfills. |
|
| 25 |
+ * @param callable $onRejected Invoked when the promise is rejected. |
|
| 26 |
+ * |
|
| 27 |
+ * @return PromiseInterface |
|
| 28 |
+ */ |
|
| 29 |
+ public function then( |
|
| 30 |
+ callable $onFulfilled = null, |
|
| 31 |
+ callable $onRejected = null |
|
| 32 |
+ ); |
|
| 33 |
+ |
|
| 34 |
+ /** |
|
| 35 |
+ * Appends a rejection handler callback to the promise, and returns a new |
|
| 36 |
+ * promise resolving to the return value of the callback if it is called, |
|
| 37 |
+ * or to its original fulfillment value if the promise is instead |
|
| 38 |
+ * fulfilled. |
|
| 39 |
+ * |
|
| 40 |
+ * @param callable $onRejected Invoked when the promise is rejected. |
|
| 41 |
+ * |
|
| 42 |
+ * @return PromiseInterface |
|
| 43 |
+ */ |
|
| 44 |
+ public function otherwise(callable $onRejected); |
|
| 45 |
+ |
|
| 46 |
+ /** |
|
| 47 |
+ * Get the state of the promise ("pending", "rejected", or "fulfilled").
|
|
| 48 |
+ * |
|
| 49 |
+ * The three states can be checked against the constants defined on |
|
| 50 |
+ * PromiseInterface: PENDING, FULFILLED, and REJECTED. |
|
| 51 |
+ * |
|
| 52 |
+ * @return string |
|
| 53 |
+ */ |
|
| 54 |
+ public function getState(); |
|
| 55 |
+ |
|
| 56 |
+ /** |
|
| 57 |
+ * Resolve the promise with the given value. |
|
| 58 |
+ * |
|
| 59 |
+ * @param mixed $value |
|
| 60 |
+ * |
|
| 61 |
+ * @throws \RuntimeException if the promise is already resolved. |
|
| 62 |
+ */ |
|
| 63 |
+ public function resolve($value); |
|
| 64 |
+ |
|
| 65 |
+ /** |
|
| 66 |
+ * Reject the promise with the given reason. |
|
| 67 |
+ * |
|
| 68 |
+ * @param mixed $reason |
|
| 69 |
+ * |
|
| 70 |
+ * @throws \RuntimeException if the promise is already resolved. |
|
| 71 |
+ */ |
|
| 72 |
+ public function reject($reason); |
|
| 73 |
+ |
|
| 74 |
+ /** |
|
| 75 |
+ * Cancels the promise if possible. |
|
| 76 |
+ * |
|
| 77 |
+ * @link https://github.com/promises-aplus/cancellation-spec/issues/7 |
|
| 78 |
+ */ |
|
| 79 |
+ public function cancel(); |
|
| 80 |
+ |
|
| 81 |
+ /** |
|
| 82 |
+ * Waits until the promise completes if possible. |
|
| 83 |
+ * |
|
| 84 |
+ * Pass $unwrap as true to unwrap the result of the promise, either |
|
| 85 |
+ * returning the resolved value or throwing the rejected exception. |
|
| 86 |
+ * |
|
| 87 |
+ * If the promise cannot be waited on, then the promise will be rejected. |
|
| 88 |
+ * |
|
| 89 |
+ * @param bool $unwrap |
|
| 90 |
+ * |
|
| 91 |
+ * @return mixed |
|
| 92 |
+ * |
|
| 93 |
+ * @throws \LogicException if the promise has no wait function or if the |
|
| 94 |
+ * promise does not settle after waiting. |
|
| 95 |
+ */ |
|
| 96 |
+ public function wait($unwrap = true); |
|
| 97 |
+} |