-
Notifications
You must be signed in to change notification settings - Fork 24
How async await works
Devrath edited this page Oct 10, 2021
·
6 revisions
- One of the biggest challenges in asynchronous programming is returning values from it.
- This is a challenge because once you call the function, you don't know when to return.
- This is hard to achieve on communicating between the threads.
- Using the
async/await
pattern we can perform tasks inparallel
. - Tasks that are
not blocking
. - Best part is they can return the values.
- Using the
promise
pattern- There the flow is like
then(do something)
-->then(do something)
-->then(do something)
--> . --> catch(if errors) - As simply explained in above flow, we perform action after action and during this time if there is any error, we catch the error down the stream in catch block
- Disadvantages associated with promise for android include, Since the promise doesn't return a value and returns a promise, This is not suitable for android type of programming.
- There the flow is like
- Using the
future
pattern