Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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