| 1 |
<?php |
| 2 |
|
| 3 |
namespace React\Dns\Query; |
| 4 |
|
| 5 |
use React\EventLoop\LoopInterface; |
| 6 |
use React\Promise\Timer; |
| 7 |
|
| 8 |
final class TimeoutExecutor implements ExecutorInterface |
| 9 |
{ |
| 10 |
private $executor; |
| 11 |
private $loop; |
| 12 |
private $timeout; |
| 13 |
|
| 14 |
public function __construct(ExecutorInterface $executor, $timeout, LoopInterface $loop) |
| 15 |
{ |
| 16 |
$this->executor = $executor; |
| 17 |
$this->loop = $loop; |
| 18 |
$this->timeout = $timeout; |
| 19 |
} |
| 20 |
|
| 21 |
public function query(Query $query) |
| 22 |
{ |
| 23 |
return Timer\timeout($this->executor->query($query), $this->timeout, $this->loop)->then(null, function ($e) use ($query) { |
| 24 |
if ($e instanceof Timer\TimeoutException) { |
| 25 |
$e = new TimeoutException(sprintf("DNS query for %s timed out", $query->name), 0, $e); |
| 26 |
} |
| 27 |
throw $e; |
| 28 |
}); |
| 29 |
} |
| 30 |
} |