Menu
Reference
- Manticore\Ds
- Async
- Classes
- AggregateError
- CancellationToken
- CancelledException
- Channel
- ChannelClosedException
- Context
- DeadlockException
- Mutex
- Once
- Pool
- Received
- SelectCase
- Selected
- Semaphore
- Settled
- Task
- TaskGroup
- TimeoutException
- Functions
- async()
- awaitAll()
- awaitAllSettled()
- awaitAny()
- channel()
- delay()
- dump()
- dumpOn()
- failure()
- group()
- mapConcurrent()
- mapSettled()
- readFile()
- select()
- selectNow()
- selectWithin()
- shield()
- shutdownOn()
- spawn()
- stats()
- timeout()
- watchdog()
- writeFile()
- Http
- Http\WebSocket
- Buffer
- Process
- Io\Poll
- Manticore\Sapi
- Ffi
delay()
function
function delay(float $seconds): void
Suspend the current task for $seconds without blocking the loop.
Other tasks run meanwhile. delay(0.0) gives them a turn and returns. The wait is on a monotonic clock. Under the scheduler, sleep() and usleep() behave the same way.
Parameters
$secondsfloat- how long to wait, in seconds
Throws
- CancelledException
- when the task is cancelled
Example
use function Async\async;
use function Async\delay;
use function Async\spawn;
// async() runs the callable on the engine and returns its value.
$total = async(function () {
// spawn() starts a task in the current scope and returns a handle.
$slow = spawn(function () {
delay(0.02);
return 10;
});
$fast = spawn(function () {
delay(0.01);
return 32;
});
// await() suspends this task (not the process) until the other one settles.
return $slow->await() + $fast->await();
});
echo "total: $total\n";Output
total: 42