Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 675 Bytes

README.md

File metadata and controls

30 lines (22 loc) · 675 Bytes

Simple Serialized Asynchronous Tasks

Subclass of NSOperation to perform serialized async blocks of tasks.

Like Promises, but dead simple.

let queue = NSOperationQueue()
queue.maxConcurrentOperationCount = 1

let operation1 = ATSerialOperation({ task in
    NSThread.sleepForTimeInterval(2)
    task.finish()
})

let operation2 = ATSerialOperation({ task in
    if let result: AnyObject = operation1.result {}
    NSThread.sleepForTimeInterval(2)
    task.finish()
})

operation2.completionBlock = {
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
      // update UI
    })
}

queue.addOperations([operation, operation2], waitUntilFinished: false)