TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Dec 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✓ |
Maintained by Quan Vo, Wilson Ding.
GroupWork is an easy to use Swift framework that helps you orchestrate your concurrent, asynchronous functions in a clean and organized way. This helps make large functions with multiple asynchronous tasks more clear and easy to follow.
For CocoaPods, add to Podfile
:
pod 'GroupWork', '~> 0.0'
For Carthage, add to Cartfile
:
github "quanvo87/GroupWork"
For SPM, add to your package dependencies:
.package(url: "https://github.com/quanvo87/GroupWork.git", .upToNextMinor(from: "0.0.0"))
GroupWork.swift
to the project treeGroupWork.xcodeproj
import GroupWork
...
func complexFunc(completion: @escaping (Bool) -> Void) {
let work = GroupWork()
work.asyncFuncA()
work.asyncFuncB()
work.asyncFuncC()
work.allDone() {
completion(work.result)
}
}
...
complexFunc
is a function that returns the result of three asynchronous functions asyncFuncA()
, asyncFuncB()
, and asyncFuncC()
, running concurrently. The completion handler is called only when all these functions have completed. Usage of this library has enabled the above clean interface. This can be scaled to much higher than three asynchronous functions.
notes:
work.result
is only a simple Bool
There is some set up required in order to create complexFunc()
from above:
import GroupWork
extension GroupWork {
func asyncFuncA() {
start()
networkCallA() { (result)
self.finish(withResult: result)
}
}
func asyncFuncB() {
start()
networkCallB() { (result)
self.finish(withResult: result)
}
}
func asyncFuncC() {
start()
networkCallC() { (result)
self.finish(withResult: result)
}
}
}
Now you can create a GroupWork
, and call work.simpleFuncA()
on it like in the example.
notes:
start()
must be called before an asynchronous taskfinish()
must be called in the completion handler of an asynchronous taskstart()
and finish()
calls must be balancedThe tests have a working example.
Please provide attribution, it is greatly appreciated.