a task queue with local persistent by Swift 2.0
Queue is a subclass of NSOperationQueue so you get:
Serial or concurrent queues Task priority Multiple queues Dependencies Task persistence (via protocol) Retries (exponential back-off)
iOS 8.0
With a good queuing solution you can provide a much better user experience in areas such as:
Web requests Saving/creating content (images, video, audio) Uploading data
The actual code to perform the task gets passed to the queue in the form of a taskHandler closure. Each QueueTask must have a taskType key which corresponds to a specific taskCallback.
For a thorough example see the demo project in the top level of the repository.
let queue = Queue(queueName: "NetWorking", maxConcurrency: 1, maxRetries: 3, serializationProvider: NSUserDefaultsSerializer(),logProvider: ConsoleLogger())
queue.addTaskCallback("Create") { (task) -> Void in
print("Create")
task.complete(nil)
}
queue.addTaskCallback("Delete") { (task) -> Void in
task.complete(nil)
}
queue.addTaskCallback("Update") { (task) -> Void in
}
queue.addTaskCallback("Select") { (task) -> Void in
}
let task = QueueTask(queue: queue, type: "Create", userInfo: nil, retries: 3)
let taskDelete = QueueTask(queue: queue, type: "Delete", userInfo: nil, retries: 3)
queue.addOperation(taskDelete)
queue.addOperation(task)