Skip to content

How async await works

Devrath edited this page Oct 10, 2021 · 6 revisions

Challenge in asynchronous code

  • 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.

Leveraging async/await pattern

  • Using the async/await pattern we can perform tasks in parallel.
  • Tasks that are not blocking.
  • Best part is they can return the values.

Inspiration to async/await pattern

  • 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.
  • Using the future pattern
Clone this wiki locally