2 namespace GuzzleHttp\Promise;
5 * A promise represents the eventual result of an asynchronous operation.
7 * The primary way of interacting with a promise is through its then method,
8 * which registers callbacks to receive either a promise’s eventual value or
9 * the reason why the promise cannot be fulfilled.
11 * @link https://promisesaplus.com/
13 interface PromiseInterface
15 const PENDING = 'pending';
16 const FULFILLED = 'fulfilled';
17 const REJECTED = 'rejected';
20 * Appends fulfillment and rejection handlers to the promise, and returns
21 * a new promise resolving to the return value of the called handler.
23 * @param callable $onFulfilled Invoked when the promise fulfills.
24 * @param callable $onRejected Invoked when the promise is rejected.
26 * @return PromiseInterface
29 callable $onFulfilled = null,
30 callable $onRejected = null
34 * Appends a rejection handler callback to the promise, and returns a new
35 * promise resolving to the return value of the callback if it is called,
36 * or to its original fulfillment value if the promise is instead
39 * @param callable $onRejected Invoked when the promise is rejected.
41 * @return PromiseInterface
43 public function otherwise(callable $onRejected);
46 * Get the state of the promise ("pending", "rejected", or "fulfilled").
48 * The three states can be checked against the constants defined on
49 * PromiseInterface: PENDING, FULFILLED, and REJECTED.
53 public function getState();
56 * Resolve the promise with the given value.
59 * @throws \RuntimeException if the promise is already resolved.
61 public function resolve($value);
64 * Reject the promise with the given reason.
66 * @param mixed $reason
67 * @throws \RuntimeException if the promise is already resolved.
69 public function reject($reason);
72 * Cancels the promise if possible.
74 * @link https://github.com/promises-aplus/cancellation-spec/issues/7
76 public function cancel();
79 * Waits until the promise completes if possible.
81 * Pass $unwrap as true to unwrap the result of the promise, either
82 * returning the resolved value or throwing the rejected exception.
84 * If the promise cannot be waited on, then the promise will be rejected.
89 * @throws \LogicException if the promise has no wait function or if the
90 * promise does not settle after waiting.
92 public function wait($unwrap = true);