Instance Method
schedule(after:_:)
Schedules work to run once after duration elapses, then returns immediately.
func schedule(after duration: Duration, _ work: @escaping @Sendable () -> Void)
Parameters
-
duration
-
How long to wait. Negative or zero durations fire on the next loop iteration.
-
work
-
Closure to invoke. Runs in the loop’s callback context.
Mentioned In
Discussion
Wraps libevent’s event_base_once(3) with EV_TIMEOUT. The closure runs on whichever task next drives the loop (via run() or any Socket / ServerSocket operation that calls runOnce() internally). If nothing drives the loop before the deadline, the callback is queued but does not fire until something does.
See Also
sleep(for:) for an async shape that suspends the calling task.