Debian Codegraph @

vendor/clue/connection-manager-extra/src/ConnectionManagerDelay.php

raw
1 <?php
2
3 namespace ConnectionManager\Extra;
4
5 use React\EventLoop\Loop;
6 use React\EventLoop\LoopInterface;
7 use React\Promise\Timer;
8 use React\Socket\ConnectorInterface;
9
10 class ConnectionManagerDelay implements ConnectorInterface
11 {
12 /** @var ConnectorInterface */
13 private $connectionManager;
14
15 /** @var float */
16 private $delay;
17
18 /** @var LoopInterface */
19 private $loop;
20
21 /**
22 * @param ConnectorInterface $connectionManager
23 * @param float $delay
24 * @param ?LoopInterface $loop
25 */
26 public function __construct(ConnectorInterface $connectionManager, $delay, $loop = null)
27 {
28 if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
29 throw new \InvalidArgumentException('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
30 }
31
32 $this->connectionManager = $connectionManager;
33 $this->delay = $delay;
34 $this->loop = $loop ?: Loop::get();
35 }
36
37 public function connect($uri)
38 {
39 $connectionManager = $this->connectionManager;
40
41 return Timer\resolve($this->delay, $this->loop)->then(function () use ($connectionManager, $uri) {
42 return $connectionManager->connect($uri);
43 });
44 }
45 }