Passed
Push — master ( d68e66...3a2ed0 )
by PHPinnacle
03:05
created

AmpTask::cancel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of PHPinnacle/Ensign.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types = 1);
12
13
namespace PHPinnacle\Ensign\Amp;
14
15
use Amp\Promise;
16
use PHPinnacle\Ensign\Task;
17
18
final class AmpTask implements Promise, Task
19
{
20
    /**
21
     * @var Promise
22
     */
23
    private $promise;
24
25
    /**
26
     * @var AmpToken
27
     */
28
    private $token;
29
30
    /**
31
     * @param Promise   $promise
32
     * @param AmpToken $token
33
     */
34 9
    public function __construct(Promise $promise, AmpToken $token)
35
    {
36 9
        $this->promise = $promise;
37 9
        $this->token   = $token;
38 9
    }
39
40
    /**
41
     * @return void
42
     */
43 1
    public function cancel(): void
44
    {
45 1
        $this->token->cancel();
46 1
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 9
    public function onResolve(callable $onResolved)
52
    {
53 9
        $this->token->guard();
54 8
        $this->promise->onResolve($onResolved);
55 8
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 1
    public function then(callable $then): void
61
    {
62 1
        $this->onResolve($then);
63 1
    }
64
}
65