{"_id":"567400df22cd7e0d00fada7f","category":{"_id":"567400638565060d009a86fb","__v":7,"pages":["567400df22cd7e0d00fada7f","56740103f65d9c0d002e3d5e","5674010f47f7010d005bff1a","56740128f79ca90d00ad2f65","5674014947f7010d005bff1c","5674015622cd7e0d00fada81","5674016058c4890d00bb5558"],"project":"5672fc989996590d00c22c65","version":"5672fc989996590d00c22c68","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-18T12:47:31.547Z","from_sync":false,"order":2,"slug":"available-operations","title":"Available Operations"},"version":{"_id":"5672fc989996590d00c22c68","__v":7,"project":"5672fc989996590d00c22c65","createdAt":"2015-12-17T18:19:04.699Z","releaseDate":"2015-12-17T18:19:04.699Z","categories":["5672fc999996590d00c22c69","567301169d4c060d009da8b3","56730183547bee0d00997d1a","5673018a06b19d0d0010691b","567301b53054630d00fe9288","567400638565060d009a86fb","5674017bf79ca90d00ad2f67"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.5.0","version":"2.5.0"},"__v":2,"project":"5672fc989996590d00c22c65","user":"5654ea8be0d82b0d00ab5747","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-12-18T12:49:35.093Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"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.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let delayInterval = DelayOperation(interval: 1)\\nlet delayDate = DelayOperation(date: dateInTheFuture)\\nqueue.addOperations(delayInterval, delayDate)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nNote 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.\n\nInstead, `DelayOperation` is useful for delaying the executing of other operations by adding it as a dependency.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let delay = DelayOperation(interval: 2)\\nlet operation = BlockOperation { print(\\\"Hello World!\\\") }\\noperation.addDependency(delay)\\nqueue.addOperations(delay, operation)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nThis can be very useful if implementing an exponential back-off system, or other repeating task.","excerpt":"","slug":"delay-operation","type":"basic","title":"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.