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
final class Each
7
final class Each
Línea 15... Línea 17...
15
     *
17
     *
16
     * $onRejected is a function that accepts the rejection reason, iterator
18
     * $onRejected is a function that accepts the rejection reason, iterator
17
     * index, and the aggregate promise. The callback can invoke any necessary
19
     * index, and the aggregate promise. The callback can invoke any necessary
18
     * side effects and choose to resolve or reject the aggregate if needed.
20
     * side effects and choose to resolve or reject the aggregate if needed.
19
     *
21
     *
20
     * @param mixed    $iterable    Iterator or array to iterate over.
22
     * @param mixed $iterable Iterator or array to iterate over.
21
     * @param callable $onFulfilled
-
 
22
     * @param callable $onRejected
-
 
23
     *
-
 
24
     * @return PromiseInterface
-
 
25
     */
23
     */
26
    public static function of(
24
    public static function of(
27
        $iterable,
25
        $iterable,
28
        callable $onFulfilled = null,
26
        ?callable $onFulfilled = null,
29
        callable $onRejected = null
27
        ?callable $onRejected = null
30
    ) {
28
    ): PromiseInterface {
31
        return (new EachPromise($iterable, [
29
        return (new EachPromise($iterable, [
32
            'fulfilled' => $onFulfilled,
30
            'fulfilled' => $onFulfilled,
33
            'rejected'  => $onRejected
31
            'rejected' => $onRejected,
34
        ]))->promise();
32
        ]))->promise();
35
    }
33
    }
Línea 36... Línea 34...
36
 
34
 
37
    /**
35
    /**
Línea 42... Línea 40...
42
     * pending promises and returns a numeric concurrency limit value to allow
40
     * pending promises and returns a numeric concurrency limit value to allow
43
     * for dynamic a concurrency size.
41
     * for dynamic a concurrency size.
44
     *
42
     *
45
     * @param mixed        $iterable
43
     * @param mixed        $iterable
46
     * @param int|callable $concurrency
44
     * @param int|callable $concurrency
47
     * @param callable     $onFulfilled
-
 
48
     * @param callable     $onRejected
-
 
49
     *
-
 
50
     * @return PromiseInterface
-
 
51
     */
45
     */
52
    public static function ofLimit(
46
    public static function ofLimit(
53
        $iterable,
47
        $iterable,
54
        $concurrency,
48
        $concurrency,
55
        callable $onFulfilled = null,
49
        ?callable $onFulfilled = null,
56
        callable $onRejected = null
50
        ?callable $onRejected = null
57
    ) {
51
    ): PromiseInterface {
58
        return (new EachPromise($iterable, [
52
        return (new EachPromise($iterable, [
59
            'fulfilled'   => $onFulfilled,
53
            'fulfilled' => $onFulfilled,
60
            'rejected'    => $onRejected,
54
            'rejected' => $onRejected,
61
            'concurrency' => $concurrency
55
            'concurrency' => $concurrency,
62
        ]))->promise();
56
        ]))->promise();
63
    }
57
    }
Línea 64... Línea 58...
64
 
58
 
65
    /**
59
    /**
66
     * Like limit, but ensures that no promise in the given $iterable argument
60
     * Like limit, but ensures that no promise in the given $iterable argument
67
     * is rejected. If any promise is rejected, then the aggregate promise is
61
     * is rejected. If any promise is rejected, then the aggregate promise is
68
     * rejected with the encountered rejection.
62
     * rejected with the encountered rejection.
69
     *
63
     *
70
     * @param mixed        $iterable
64
     * @param mixed        $iterable
71
     * @param int|callable $concurrency
-
 
72
     * @param callable     $onFulfilled
-
 
73
     *
-
 
74
     * @return PromiseInterface
65
     * @param int|callable $concurrency
75
     */
66
     */
76
    public static function ofLimitAll(
67
    public static function ofLimitAll(
77
        $iterable,
68
        $iterable,
78
        $concurrency,
69
        $concurrency,
79
        callable $onFulfilled = null
70
        ?callable $onFulfilled = null
80
    ) {
71
    ): PromiseInterface {
81
        return each_limit(
72
        return self::ofLimit(
82
            $iterable,
73
            $iterable,
83
            $concurrency,
74
            $concurrency,
84
            $onFulfilled,
75
            $onFulfilled,
85
            function ($reason, $idx, PromiseInterface $aggregate) {
76
            function ($reason, $idx, PromiseInterface $aggregate): void {
86
                $aggregate->reject($reason);
77
                $aggregate->reject($reason);
87
            }
78
            }
88
        );
79
        );
89
    }
80
    }