TaskSystem/vendor/guzzlehttp/promises/src/PromiseInterface.php

98 lines
2.8 KiB
PHP
Raw Normal View History

2023-07-15 10:16:32 +08:00
<?php
namespace GuzzleHttp\Promise;
/**
* A promise represents the eventual result of an asynchronous operation.
*
* The primary way of interacting with a promise is through its then method,
* which registers callbacks to receive either a promises eventual value or
* the reason why the promise cannot be fulfilled.
*
2023-07-18 11:17:17 +08:00
* @link https://promisesaplus.com/
2023-07-15 10:16:32 +08:00
*/
interface PromiseInterface
{
2023-07-18 11:17:17 +08:00
const PENDING = 'pending';
const FULFILLED = 'fulfilled';
const REJECTED = 'rejected';
2023-07-15 10:16:32 +08:00
/**
* Appends fulfillment and rejection handlers to the promise, and returns
* a new promise resolving to the return value of the called handler.
*
* @param callable $onFulfilled Invoked when the promise fulfills.
* @param callable $onRejected Invoked when the promise is rejected.
2023-07-18 11:17:17 +08:00
*
* @return PromiseInterface
2023-07-15 10:16:32 +08:00
*/
public function then(
callable $onFulfilled = null,
callable $onRejected = null
2023-07-18 11:17:17 +08:00
);
2023-07-15 10:16:32 +08:00
/**
* Appends a rejection handler callback to the promise, and returns a new
* promise resolving to the return value of the callback if it is called,
* or to its original fulfillment value if the promise is instead
* fulfilled.
*
* @param callable $onRejected Invoked when the promise is rejected.
2023-07-18 11:17:17 +08:00
*
* @return PromiseInterface
2023-07-15 10:16:32 +08:00
*/
2023-07-18 11:17:17 +08:00
public function otherwise(callable $onRejected);
2023-07-15 10:16:32 +08:00
/**
* Get the state of the promise ("pending", "rejected", or "fulfilled").
*
* The three states can be checked against the constants defined on
* PromiseInterface: PENDING, FULFILLED, and REJECTED.
2023-07-18 11:17:17 +08:00
*
* @return string
2023-07-15 10:16:32 +08:00
*/
2023-07-18 11:17:17 +08:00
public function getState();
2023-07-15 10:16:32 +08:00
/**
* Resolve the promise with the given value.
*
* @param mixed $value
*
* @throws \RuntimeException if the promise is already resolved.
*/
2023-07-18 11:17:17 +08:00
public function resolve($value);
2023-07-15 10:16:32 +08:00
/**
* Reject the promise with the given reason.
*
* @param mixed $reason
*
* @throws \RuntimeException if the promise is already resolved.
*/
2023-07-18 11:17:17 +08:00
public function reject($reason);
2023-07-15 10:16:32 +08:00
/**
* Cancels the promise if possible.
*
2023-07-18 11:17:17 +08:00
* @link https://github.com/promises-aplus/cancellation-spec/issues/7
2023-07-15 10:16:32 +08:00
*/
2023-07-18 11:17:17 +08:00
public function cancel();
2023-07-15 10:16:32 +08:00
/**
* Waits until the promise completes if possible.
*
* Pass $unwrap as true to unwrap the result of the promise, either
* returning the resolved value or throwing the rejected exception.
*
* If the promise cannot be waited on, then the promise will be rejected.
*
2023-07-18 11:17:17 +08:00
* @param bool $unwrap
*
2023-07-15 10:16:32 +08:00
* @return mixed
*
* @throws \LogicException if the promise has no wait function or if the
* promise does not settle after waiting.
*/
2023-07-18 11:17:17 +08:00
public function wait($unwrap = true);
2023-07-15 10:16:32 +08:00
}