A tiny and simple Swift Promise library, written in 33 lines of code 🏄♂️
MIT License
A very simple Swift 3.0 Promise library I've written while on the plane using my iPad and Playgrounds.
Writte in just 33 lines of code.
Rather simple and more for reference than actually to be used is this very simple implementation of a Promise framework.
Succeeding
Promise<String> { resolve, reject in
resolve("Bazingaaaa!")
}.then { result in
print(result) // Bazingaaaa!
}
Failing
Promise<String> { resolve, reject in
reject(Error.AnError)
}.fail { error in
print("An error occured \(error)")
}
Chaining
Promise<String> { resolve, reject in
resolve(1)
}.then { result -> Promise<Int> in
return Promise<Int> { resolve, reject in
resolve(result + 1)
}
}.then { result -> Promise<Int> in
return Promise<Int> { resolve, reject in
resolve(result + 1)
}
}.then { result in
print(result) // 3
}
Please take a moment to read and understand the Berlin Code of Conduct.
See LICENSE.md