Swift — Write beautiful Async code, with Promises
Async code sucks…
It is hard to write, hard to read, hard to reason about.
A pain to maintain
Enters then 🎬
By using a then keyword that enables you to write aSync code that reads like an English sentence.
Async code becomes concise, flexible, maintainable. And dare I say beautiful ❤️
Writing your own Promise 💪
Wondering what fetchUserId() is?
It is a simple function that returns a strongly typed promise :
Here you would typically replace the dummy doSomethingAsync function by your network request ❤
Now you can use it like so :
Bonus 🤓
If we want this to be beautiful, it should read like an english sentence
We can do this by extracting our blocks into separate functions :
#goodbyeCallbackHell
For more info checkout the github repo here :
then 🎬, an Elegant Async code for Swift library
More goodness ❤️
then is part of a series of lightweight libraries aiming to make developing iOS Apps a breeze :