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

27 lines
684 B
PHP
Raw Normal View History

2015-03-18 19:04:18 +01:00
<?php
namespace Amp;
2015-07-30 05:23:53 +02:00
/**
* Coroutines can yield Pause objects to suspend execution until the specified timeout elapses
*/
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
2015-07-29 07:15:43 +02:00
* @throws \DomainException On invalid timeout value
2015-07-21 04:24:51 +02:00
*/
2015-07-29 07:15:43 +02:00
public function __construct($timeout) {
2015-07-21 04:24:51 +02:00
$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
}
2015-07-29 07:15:43 +02:00
once(function () {
2015-07-21 04:24:51 +02:00
$this->resolve();
}, $timeout);
2015-03-18 19:04:18 +01:00
}
}