File: CallbackPromiseAdapter.php

package info (click to toggle)
php-react-promise 3.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 832 kB
  • sloc: php: 3,457; makefile: 22
file content (46 lines) | stat: -rw-r--r-- 936 bytes parent folder | download | duplicates (2)
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 React\Promise\PromiseAdapter;

use React\Promise\PromiseInterface;

/**
 * @template T
 * @template-implements PromiseAdapterInterface<T>
 */
class CallbackPromiseAdapter implements PromiseAdapterInterface
{
    /** @var callable[] */
    private $callbacks;

    /**
     * @param callable[] $callbacks
     */
    public function __construct(array $callbacks)
    {
        $this->callbacks = $callbacks;
    }

    /**
     * @return PromiseInterface<T>
     */
    public function promise(): PromiseInterface
    {
        return ($this->callbacks['promise'])(...func_get_args());
    }

    public function resolve($value): void
    {
        ($this->callbacks['resolve'])(...func_get_args());
    }

    public function reject(): void
    {
        ($this->callbacks['reject'])(...func_get_args());
    }

    public function settle(): void
    {
        ($this->callbacks['settle'])(...func_get_args());
    }
}