Skip to content

Commit 050aaa7

Browse files
authored
Update README.md
1 parent 4a6da52 commit 050aaa7

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<img title="Build status" src="https://travis-ci.org/THREDOpenSource/SYNQueue.svg">
1010
</div>
1111

12-
##Overview
12+
## Overview
1313

1414
`SYNQueue` is a subclass of `NSOperationQueue` so you get:
1515

@@ -26,22 +26,22 @@
2626
- Queue specific logging (via protocol)
2727
- Retries (exponential back-off)
2828

29-
##Motivation
29+
## Motivation
3030
With a good queuing solution you can provide a much better user experience in areas such as:
3131

3232
- Web requests
3333
- Saving/creating content (images, video, audio)
3434
- Uploading data
3535

36-
##Architecture
36+
## Architecture
3737
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.
3838

3939
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`.
4040

41-
##Example Code
41+
## Example Code
4242
For a thorough example see the demo project in the top level of the repository.
4343

44-
###Create a queue
44+
### Create a queue
4545
```swift
4646
let queue = SYNQueue(queueName: "myQueue", maxConcurrency: 2, maxRetries: 3,
4747
logProvider: ConsoleLogger(), serializationProvider: NSUserDefaultsSerializer(),
@@ -54,29 +54,28 @@ let queue = SYNQueue(queueName: "myQueue", maxConcurrency: 2, maxRetries: 3,
5454
>
5555
>The `completionBlock` is the block to run when a task in the queue completes (success or failure).
5656
57-
###Create a task
57+
### Create a task
5858
```swift
5959
let t1 = SYNQueueTask(queue: queue, taskID: "1234", taskType: "uploadPhoto", dependencyStrs: [], data: [:])
6060
```
6161

6262
>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.
6363
64-
###Add dependencies
64+
### Add dependencies
6565
```swift
6666
let t2 = SYNQueueTask(queue: queue, taskID: "5678", taskType: "submitForm", dependencyStrs: [], data: [:])
6767
t2.addDependency(t1)
6868
```
6969

70-
###Add it to the queue
70+
### Add it to the queue
7171
```swift
7272
queue.addOperation(t2)
7373
queue.addOperation(t1)
7474
```
7575

7676
>Notice that even though we add task `t2` to the queue first, it will not execute until its dependency, `t1` has finished executing.`
77-
>
7877
79-
##An important note on persistence
78+
## An important note on persistence
8079
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.
8180

8281
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

Comments
 (0)