CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Sep 2015 |
| SPMSupports SPM | ✗ |
Maintained by John Hurliman, Sidhant Gandhi.
SYNQueue is a subclass of NSOperationQueue so you get:
But it goes beyond NSOperationQueue and NSOperation to offer:
With a good queuing solution you can provide a much better user experience in areas such as:
When we started building SYNQueue, persistence was the most important feature for us since we hadn’t seen a good generic implementation of it anywhere. With that in mind, we designed each SYNQueueTask (:NSOperation) to hold just metadata about the task rather than code itself.
The actual code to perform the task gets passed to the queue in the form of a taskHandler closure. Each SYNQueueTask must have a taskType key which corresponds to a specific taskHandler.
For a thorough example see the demo project in the top level of the repository.
let queue = SYNQueue(queueName: "myQueue", maxConcurrency: 2, maxRetries: 3,
logProvider: ConsoleLogger(), serializationProvider: NSUserDefaultsSerializer(),
completionBlock: { [weak self] in self?.taskComplete($0, $1) })The
logProviderandserializationProvidermust conform to theSYNQueueLogProviderandSYNQueueSerializationProviderprotocols respectively.See NSUserDefaultsSerializer.swift and ConsoleLogger.swift for example implementations.
The
completionBlockis the block to run when a task in the queue completes (success or failure).
let t1 = SYNQueueTask(queue: queue, taskID: "1234", taskType: "uploadPhoto", dependencyStrs: [], data: [:])The
queueis the queue you will add the task to.taskIDis a unique ID for the task.taskTypeis the generic type of task to perform. EachtaskTypewill have its owntaskHandler.datais any metadata your task will need to perform its job.
let t2 = SYNQueueTask(queue: queue, taskID: "5678", taskType: "submitForm", dependencyStrs: [], data: [:])
t2.addDependency(t1)queue.addOperation(t2)
queue.addOperation(t1)Notice that even though we add task
t2to the queue first, it will not execute until its dependency,t1has finished executing.`
You may have realized that you are free to serialize tasks however you like through the SYNQueueSerializationProvider protocol. The one caveat is that all tasks must be idempotent. That is, even if called multiple times, the outcome of the task should be the same. For example: x = 1 is idempotent, x++ is not.
Hopefully this makes sense given that a serialized task may get interrupted before it finishes, and when we deserialize this task we will run it again. We only remove the serialized task after it has completed (success or failure).