3 ms·
Shameless plug for my tiny implementation of Promise (similar to the Future type mentioned in the article)[1]. I've used it in a few projects, and it makes dea
by Sidnicious 11y ago
Shameless plug for my tiny implementation of Promise (similar to the Future type mentioned in the article)[1].
I've used it in a few projects, and it makes dealing with async things feel surprisingly natural:
getLocation()
.then { apiRequest(params, location: $0) }
.then { json -> () in
for result in json["results"] {
display(result)
}
}
.catch { showError($0) }
It's also easy trivial to adapt existing callback-based[2] and delegate-based[3] APIs to promises.
[1]: https://gist.github.com/Sidnicious/93d2a8db1266e2fd239c https://gist.github.com/Sidnicious/93d2a8db1266e2fd239c
[2]: https://gist.github.com/Sidnicious/69df2c483aadc08bda4f https://gist.github.com/Sidnicious/69df2c483aadc08bda4f
[3]: https://gist.github.com/Sidnicious/99b099d9b6f2ecb9e383 https://gist.github.com/Sidnicious/99b099d9b6f2ecb9e383