1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Client\Time;
15:
16: use Amp\Cancellation;
17: use Nexus\Clock\Microseconds;
18:
19: use function Amp\delay;
20:
21: /**
22: * A delay that suspends the current fiber on the event loop.
23: */
24: final readonly class EventLoopDelay implements CancellableDelayInterface
25: {
26: #[\Override]
27: public function sleep(float|int $seconds, ?Cancellation $cancellation = null): void
28: {
29: if (Microseconds::fromSeconds($seconds) < 1) {
30: $cancellation?->throwIfRequested();
31:
32: return;
33: }
34:
35: delay($seconds, cancellation: $cancellation);
36: }
37: }
38: