forked from frodeborli/moebius-promise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PromiseInterface.php
46 lines (40 loc) · 1.57 KB
/
PromiseInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Moebius;
/**
* A pure promise interface, designed for interoperability. This interface can
* be implemented by most known promise implementations, including React, Amp
* and GuzzleHttp.
*
* The rationale for the design of this interface is that it provides all the
* neccesary functionality to retrieve a future value for any consumer of the
* promise. Other functionality such as promise resolution is particular to the
* source that created the promise.
*
* The `then()` method allows a third argument because some promise implementations
* implement alternative semantics such as progress-updates or on-cancellation.
*
*/
interface PromiseInterface {
/**
* Schedule a callback to run when the promise is fulfilled
* or rejected.
*
* @param callable $onFulfill Callback which will be invoked if the promise is fulfilled.
* @param callable $onReject Callback which will be invoked if the promise is rejected.
* @param callable $void Ignored; for compataiblity with other promise implementations.
* @return PromiseInterface Returns a new promise which is resolved with the return value of $onFulfill/$onReject
*/
public function then(callable $onFulfill=null, callable $onReject=null, callable $void=null): PromiseInterface;
/**
* Is the promise still pending resolution?
*/
public function isPending(): bool;
/**
* Is the promise fulfilled?
*/
public function isFulfilled(): bool;
/**
* Is the promise rejected?
*/
public function isRejected(): bool;
}