SkillAgentSearch skills...

SPKit

Simple Promise Kit for swift

Install / Use

/learn @piresbruno/SPKit
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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

How to install SPKit

You can install SPKit using carthage, or just drag the SPKit.swift file to your project.

How to use SPKit

Start the flow by calling SPKit.first, move to the next block by calling .resolve() and finish the flow by calling .complete() or .failure().

Example happy path

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")
}

Example happy path with sync and async

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")
}

Example error path

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")
}
Doubts or questions

Please open an issue.

Build Carthage compatible Swift version platforms

Related Skills

View on GitHub
GitHub Stars8
CategoryDevelopment
Updated3y ago
Forks0

Languages

Swift

Security Score

70/100

Audited on May 1, 2022

No findings