friendship ended with social-app. php is my new best friend
1<?php 2 3namespace React\Promise; 4 5/** 6 * @template-covariant T 7 */ 8interface PromiseInterface 9{ 10 /** 11 * Transforms a promise's value by applying a function to the promise's fulfillment 12 * or rejection value. Returns a new promise for the transformed result. 13 * 14 * The `then()` method registers new fulfilled and rejection handlers with a promise 15 * (all parameters are optional): 16 * 17 * * `$onFulfilled` will be invoked once the promise is fulfilled and passed 18 * the result as the first argument. 19 * * `$onRejected` will be invoked once the promise is rejected and passed the 20 * reason as the first argument. 21 * 22 * It returns a new promise that will fulfill with the return value of either 23 * `$onFulfilled` or `$onRejected`, whichever is called, or will reject with 24 * the thrown exception if either throws. 25 * 26 * A promise makes the following guarantees about handlers registered in 27 * the same call to `then()`: 28 * 29 * 1. Only one of `$onFulfilled` or `$onRejected` will be called, 30 * never both. 31 * 2. `$onFulfilled` and `$onRejected` will never be called more 32 * than once. 33 * 34 * @template TFulfilled 35 * @template TRejected 36 * @param ?(callable((T is void ? null : T)): (PromiseInterface<TFulfilled>|TFulfilled)) $onFulfilled 37 * @param ?(callable(\Throwable): (PromiseInterface<TRejected>|TRejected)) $onRejected 38 * @return PromiseInterface<($onRejected is null ? ($onFulfilled is null ? T : TFulfilled) : ($onFulfilled is null ? T|TRejected : TFulfilled|TRejected))> 39 */ 40 public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface; 41 42 /** 43 * Registers a rejection handler for promise. It is a shortcut for: 44 * 45 * ```php 46 * $promise->then(null, $onRejected); 47 * ``` 48 * 49 * Additionally, you can type hint the `$reason` argument of `$onRejected` to catch 50 * only specific errors. 51 * 52 * @template TThrowable of \Throwable 53 * @template TRejected 54 * @param callable(TThrowable): (PromiseInterface<TRejected>|TRejected) $onRejected 55 * @return PromiseInterface<T|TRejected> 56 */ 57 public function catch(callable $onRejected): PromiseInterface; 58 59 /** 60 * Allows you to execute "cleanup" type tasks in a promise chain. 61 * 62 * It arranges for `$onFulfilledOrRejected` to be called, with no arguments, 63 * when the promise is either fulfilled or rejected. 64 * 65 * * If `$promise` fulfills, and `$onFulfilledOrRejected` returns successfully, 66 * `$newPromise` will fulfill with the same value as `$promise`. 67 * * If `$promise` fulfills, and `$onFulfilledOrRejected` throws or returns a 68 * rejected promise, `$newPromise` will reject with the thrown exception or 69 * rejected promise's reason. 70 * * If `$promise` rejects, and `$onFulfilledOrRejected` returns successfully, 71 * `$newPromise` will reject with the same reason as `$promise`. 72 * * If `$promise` rejects, and `$onFulfilledOrRejected` throws or returns a 73 * rejected promise, `$newPromise` will reject with the thrown exception or 74 * rejected promise's reason. 75 * 76 * `finally()` behaves similarly to the synchronous finally statement. When combined 77 * with `catch()`, `finally()` allows you to write code that is similar to the familiar 78 * synchronous catch/finally pair. 79 * 80 * Consider the following synchronous code: 81 * 82 * ```php 83 * try { 84 * return doSomething(); 85 * } catch(\Exception $e) { 86 * return handleError($e); 87 * } finally { 88 * cleanup(); 89 * } 90 * ``` 91 * 92 * Similar asynchronous code (with `doSomething()` that returns a promise) can be 93 * written: 94 * 95 * ```php 96 * return doSomething() 97 * ->catch('handleError') 98 * ->finally('cleanup'); 99 * ``` 100 * 101 * @param callable(): (void|PromiseInterface<void>) $onFulfilledOrRejected 102 * @return PromiseInterface<T> 103 */ 104 public function finally(callable $onFulfilledOrRejected): PromiseInterface; 105 106 /** 107 * The `cancel()` method notifies the creator of the promise that there is no 108 * further interest in the results of the operation. 109 * 110 * Once a promise is settled (either fulfilled or rejected), calling `cancel()` on 111 * a promise has no effect. 112 * 113 * @return void 114 */ 115 public function cancel(): void; 116 117 /** 118 * [Deprecated] Registers a rejection handler for a promise. 119 * 120 * This method continues to exist only for BC reasons and to ease upgrading 121 * between versions. It is an alias for: 122 * 123 * ```php 124 * $promise->catch($onRejected); 125 * ``` 126 * 127 * @template TThrowable of \Throwable 128 * @template TRejected 129 * @param callable(TThrowable): (PromiseInterface<TRejected>|TRejected) $onRejected 130 * @return PromiseInterface<T|TRejected> 131 * @deprecated 3.0.0 Use catch() instead 132 * @see self::catch() 133 */ 134 public function otherwise(callable $onRejected): PromiseInterface; 135 136 /** 137 * [Deprecated] Allows you to execute "cleanup" type tasks in a promise chain. 138 * 139 * This method continues to exist only for BC reasons and to ease upgrading 140 * between versions. It is an alias for: 141 * 142 * ```php 143 * $promise->finally($onFulfilledOrRejected); 144 * ``` 145 * 146 * @param callable(): (void|PromiseInterface<void>) $onFulfilledOrRejected 147 * @return PromiseInterface<T> 148 * @deprecated 3.0.0 Use finally() instead 149 * @see self::finally() 150 */ 151 public function always(callable $onFulfilledOrRejected): PromiseInterface; 152}