Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Why Kotlin Coroutines are a blessing for Android devs

Why Kotlin Coroutines are a blessing for Android devs

Muhammad Zeeshan Shabbir

April 12, 2019
Tweet

Other Decks in Programming

Transcript

  1. Hello I am Muhammad Zeeshan Shabbir. Android Enthusiast, 3+ years

    of software industry experience. Deeply passionate about SDLC and crafting amazing apps that can solve real world problem
  2. History • First introduced by Simula 67 • Detach (Coroutine

    suspension statement). • Resume (Coroutine execution statement). • Multithreading • Still in use by C# and JavaScript • Back again with Kotlin coroutine.
  3. What are Kotlin coroutines? Coroutines are basically light weight and

    much more efficient threads. Asynchronous code looks like classic synchronous code.
  4. Synchronous and Asynchronous? Synchronous: Wait for it to finish before

    moving on to another task Asynchronous: Move on to another task before it finishes. “xx frames dropped” -> ANR
  5. Asynchronous options in Android? • Java Thread API • AsyncTasks

    • Android Serivces • Reactive Programming (Rxjava)
  6. Rxjava ▰ Learning Curve. ▰ A lot of Callbacks. ▰

    Too many operators, too large library. ▰ Exception handling & Readability.
  7. How does coroutines work? With a few key functions like

    async, await, defer, computation coroutines quickly allow you to identify which parts of your code are suspendable, which are to be executed on another thread, where to send the result of an asynchronous computation.
  8. Lighter than Threads Coroutines are lighter than threads in the

    sense that a high number of coroutines can be created and run concurrently without running out of memory
  9. Why Coroutines are blessing? ▰ Provides much Flexibility, code can

    be written into easy to understand sequential way. ▰ Light weighted. ▰ No Callbacks hell. ▰ Chaining is very easy. ▰ Exception handling & Readability is better.