Promise.kt
tl;dr
A very simple Kotlin Promise library I've written, after coming up with the same library for Swift on my iPad years ago.
Writte in just 26 lines of code.
Usage
Rather simple and more for reference than actually to be used is this very simple implementation of a Promise library.
Succeeding
Promise<String> { resolve, reject ->
resolve("Bazingaaaa!")
}.then { result ->
System.out.print(result) // Bazingaaaa!
}
Failing
Promise<String> { resolve, reject ->
reject(AnError())
}.fail { error ->
System.out.print("An error occured $error")
}
Chaining
Promise<String> { resolve, reject ->
resolve(1)
}.thenWith { result ->
return Promise<Int> { resolve, reject ->
resolve(result + 1)
}
}.thenWith { result ->
return Promise<Int> { resolve, reject ->
resolve(result + 1)
}
}.then { result ->
System.out.print(result) // 3
}
Contributing
Please take a moment to read and understand the Berlin Code of Conduct.
License
See LICENSE.md