TaskRunner is a Swift utility module which provides functions to run closures easily in series and parallel.
To run the example project, clone the repo, and run pod install from the Example directory first.
let closure0: Task = {
done in
// run a sync/async method or a job
if error != nil {
done(error)
return
}
done(nil)
}
let closure1: Task = {
done in
// run a sync/async method or a job
if error != nil {
done(error)
return
}
done(nil)
}
let closure2: Task = {
done in
// run a sync/async method or a job
if error != nil {
done(error)
return
}
done(nil)
}
let tasks = [closure0, closure1, closure2]TaskRunner.runInSeries(tasks: tasks, done: {
error in
if error != nil {
// handle error
return
}
// handle success
})closure1 and closure2 start if and only if closure0 completes it's job without an error.
TaskRunner.runInParallel(tasks: tasks, done: {
error in
if error != nil {
// handle error
return
}
// handle success
})closure0, closure1 and closure2 start running at the same time.
TaskRunner is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "TaskRunner"Zafer Sevik, zafer13 at gmail.com
TaskRunner is available under the MIT license. See the LICENSE file for more info.