1
0
mirror of https://github.com/danog/amp.git synced 2024-12-14 02:17:26 +01:00
amp/lib/Pause.php

26 lines
740 B
PHP
Raw Normal View History

2015-03-18 19:04:18 +01:00
<?php
namespace Amp;
class Pause implements Promise {
use Placeholder;
2015-07-21 04:24:51 +02:00
/**
* @param int $timeout The timeout in milliseconds after which the promise will resolve
* @param \Amp\Reactor $reactor An optional reactor instance (default reactor used if not specified)
* @throws \DomainException If
*/
public function __construct($timeout, Reactor $reactor = null) {
$timeout = (int) $timeout;
if ($timeout < 1) {
throw new \DomainException(
"Pause timeout must be greater than or equal to 1 millisecond"
);
2015-03-18 19:04:18 +01:00
}
$reactor = $reactor ?: reactor();
2015-07-21 04:24:51 +02:00
$reactor->once(function() {
$this->resolve();
}, $timeout);
2015-03-18 19:04:18 +01:00
}
}