---
agentTools:
  projectIndex: https://operations.readme.io/llms.txt
---

# Delay Operation

The `DelayOperation` inserts a delay into the queue. It does not perform any *work* itself. It can be created using either a time interval, e.g. delay for 2 seconds, or with a `NSDate` instance which must be in the future.

[block:code]
{
  "codes": [
    {
      "code": "let delayInterval = DelayOperation(interval: 1)\nlet delayDate = DelayOperation(date: dateInTheFuture)\nqueue.addOperations(delayInterval, delayDate)",
      "language": "swift"
    }
  ]
}
[/block]

Note that the above code is pretty meaningless. `DelayOperation` will only pause a serial queue, and delaying by one second, and then until a date in the future is likely redundant.

Instead, `DelayOperation` is useful for delaying the executing of other operations by adding it as a dependency.

[block:code]
{
  "codes": [
    {
      "code": "let delay = DelayOperation(interval: 2)\nlet operation = BlockOperation { print(\"Hello World!\") }\noperation.addDependency(delay)\nqueue.addOperations(delay, operation)",
      "language": "swift"
    }
  ]
}
[/block]

This can be very useful if implementing an exponential back-off system, or other repeating task.