You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`SYNQueue` is a subclass of `NSOperationQueue` so you get:
15
15
@@ -26,22 +26,22 @@
26
26
- Queue specific logging (via protocol)
27
27
- Retries (exponential back-off)
28
28
29
-
##Motivation
29
+
##Motivation
30
30
With a good queuing solution you can provide a much better user experience in areas such as:
31
31
32
32
- Web requests
33
33
- Saving/creating content (images, video, audio)
34
34
- Uploading data
35
35
36
-
##Architecture
36
+
##Architecture
37
37
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.
38
38
39
39
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`.
40
40
41
-
##Example Code
41
+
##Example Code
42
42
For a thorough example see the demo project in the top level of the repository.
43
43
44
-
###Create a queue
44
+
###Create a queue
45
45
```swift
46
46
let queue =SYNQueue(queueName: "myQueue", maxConcurrency: 2, maxRetries: 3,
>The `queue` is the queue you will add the task to. `taskID` is a unique ID for the task. `taskType` is the generic type of task to perform. Each `taskType` will have its own `taskHandler`. `data` is any data your task will need to perform its job.
>Notice that even though we add task `t2` to the queue first, it will not execute until its dependency, `t1` has finished executing.`
77
-
>
78
77
79
-
##An important note on persistence
78
+
##An important note on persistence
80
79
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.
81
80
82
81
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).
0 commit comments