Swiftpack.co - piresbruno/SPKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by piresbruno.
piresbruno/SPKit v0.6
Simple Promise Kit for swift
⭐️ 8
🕓 1 year ago
.package(url: "https://github.com/piresbruno/SPKit.git", from: "v0.6")

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

GitHub

link
Stars: 8
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics