\Co\delay
###API
namespace Co;
function delay(Closure $closure,int|float $second): string;
Parameter descriptionβ
| Parameters | Type | Description | |----------|------------------|------------------- ---| | $closure | Closure | Delayed execution of the closure function, running in the event context | | $second | int | float | Delay time, unit second, supports decimal precision of 0.1 seconds |
Closure parametersβ
none
Return valueβ
Returns the unique identifier of the event, allowing the event to be canceled using the \Co\cancel method
Overviewβ
Delay (delayed execution), executes a closure function after a certain period of time to handle asynchronous operations.
Basic usageβ
\Co\delay(function () {
echo 'delay task';
}, 1);
\Co\sleep(10); // Suspend the main process for 10 seconds so that other coroutines can complete the task
hintβ
In the scaffolding provided by ripple, most framework controller requests will occur in the async space. You can use the
\Co\delay
method in the controller.