SPKit is just another Swift promises framework, it prevents the callback hell and supports sync and async code.
It was made be to simple to use, read and maintain.
It works with Xcode 10.2 and Swift 5
You can install SPKit using carthage, or just drag the SPKit.swift file to your project.
Start the flow by calling SPKit.first
, move to the next block by calling .resolve()
and finish the flow by calling .complete()
or .failure()
.
SPKit.first { (instance) in
print("first code block")
instance.resolve()
}.then { (instance, result) in
print("next code block")
instance.complete()
}.onCompleted {(result) in
print("COMPLETED")
}.onFailure {(error) in
print("FAILURE")
}
SPKit.first { (instance) in
print("first code exec")
instance.resolve()
}.then { (instance, result) in
DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1)){
print("async code")
instance.resolve()
}
}.then { (instance, result) in
print("sync code")
instance.resolve("finished stage 2")
}.then { (instance, result) in
print("using result value: \(result as? String ?? "")")
instance.complete()
}.onCompleted {(result) in
print("COMPLETED")
}.onFailure {(error) in
print("FAILURE")
}
SPKit.first { (instance) in
print("first code exec")
instance.resolve()
}.then { (instance, result) in
print("sync code")
instance.resolve("finished stage 2")
}.then { (instance, result) in
print("using result value: \(result as? String ?? "")")
instance.failure("ooppps")
}.onCompleted {(result) in
print("COMPLETED")
}.onFailure {(error) in
print("FAILURE")
}
Please open an issue.
link |
Stars: 8 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics