JohnEstropia / GCDKit

Grand Central Dispatch simplified with swift.
MIT License
319 stars 39 forks source link

nice kit. any sample about task queue? #14

Open leancmscn opened 8 years ago

leancmscn commented 8 years ago

uploadQueen = GDDQueue("upload") uploadQueen.addTask([task1, task2, task3]).notify({

all task finished!

})

like this

JohnEstropia commented 8 years ago

@leancmscn The README file shows an example using GCDGroups: https://github.com/JohnEstropia/GCDKit#launching-and-reporting-completion-of-a-group-of-tasks

Isn't this what you are looking for?

leancmscn commented 8 years ago

GCDGroups not suit for unlimited task, only suit for tasks added one by one.

let dispatchGroup = GCDGroup()

dispatchGroup.enter()
doSomeLongTaskWithCompletion {
    dispatchGroup.leave()
}

for task in tasks {
      dispatchGroup.async(.Default) {
            task
      }
}
dispatchGroup.notify(.Main) {
    // report completion
}

right?