mirror of
https://github.com/danog/amp.git
synced 2024-12-03 09:57:51 +01:00
26 lines
741 B
PHP
26 lines
741 B
PHP
<?php
|
|
|
|
namespace Amp;
|
|
|
|
class Pause implements Promise {
|
|
use Placeholder;
|
|
|
|
/**
|
|
* @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"
|
|
);
|
|
}
|
|
$reactor = $reactor ?: reactor();
|
|
$reactor->once(function () {
|
|
$this->resolve();
|
|
}, $timeout);
|
|
}
|
|
}
|