Completed
Pull Request — master (#55)
by Timo
02:47
created

DeferredFactory::setPromiseFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the Tidal/WampWatch package.
4
 *  (c) 2016 Timo Michna <timomichna/yahoo.de>.
5
 *
6
 *  For the full copyright and license information, please view the LICENSE
7
 *  file that was distributed with this source code.
8
 */
9
10
namespace Tidal\WampWatch\Adapter\React;
11
12
use Tidal\WampWatch\Async\Adapter\PromiseFactoryInterface;
13
use React\Promise\Deferred as ReactDeferred;
14
15
class DeferredFactory
16
{
17
    /**
18
     * @var PromiseFactoryInterface
19
     */
20
    private $promiseFactory;
21
22
    public function __construct(PromiseFactoryInterface $promiseFactory)
23
    {
24
        $this->setPromiseFactory($promiseFactory);
25
    }
26
27
    /**
28
     * @param PromiseFactoryInterface $promiseFactory
29
     */
30
    private function setPromiseFactory(PromiseFactoryInterface $promiseFactory)
31
    {
32
        $this->promiseFactory = $promiseFactory;
33
    }
34
35
    /**
36
     * @return PromiseFactoryInterface
37
     */
38
    public function getPromiseFactory()
39
    {
40
        return $this->promiseFactory;
41
    }
42
43
    /**
44
     * @param callable|null $canceller
45
     *
46
     * @return DeferredAdapter
47
     */
48
    public function create(callable $canceller = null)
49
    {
50
        $adapter = new DeferredAdapter(
51
            new ReactDeferred($canceller)
52
        );
53
        $adapter->setPromiseFactory($this->getPromiseFactory());
54
55
        return $adapter;
56
    }
57
}
58