<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Event",
  "identifier" : "/documentation/Event/EventLoop/schedule(after:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Event"
    ],
    "preciseIdentifier" : "s:5Event0A4LoopC8schedule5after_ys8DurationV_yyYbctF"
  },
  "title" : "schedule(after:_:)"
}
-->

# 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.

## Discussion

Wraps libevent’s `event_base_once(3)` with `EV_TIMEOUT`. The closure runs on
whichever task next drives the loop (via [`run()`](/documentation/Event/EventLoop/run()) or any [`Socket`](/documentation/Event/Socket) /
[`ServerSocket`](/documentation/Event/ServerSocket) operation that calls [`runOnce()`](/documentation/Event/EventLoop/runOnce()) internally). If nothing
drives the loop before the deadline, the callback is queued but does not fire
until something does.

> SeeAlso: ``doc://Event/documentation/Event/EventLoop/sleep(for:)`` for an `async` shape that suspends the calling task.