SlideShare a Scribd company logo
1 of 29
Download to read offline
Tackling Asynchrony
with Kotlin Coroutines
Presented By: PRAVEER GUPTA
fun getUserAddress(userId: Long): Address { … }
fun getRestaurants(address: Address): List<Restaurant> { … }
Sync or Async?
Reactive approach to Async
fun getUserAddress(userId: Long): Single<Address> { … }
fun getRestaurants(address: Address): Single<List<Restaurant>> { … }
Wrapped return types
Kotlin Coroutine’s approach to Async
suspend fun getUserAddress(userId: Long): Address { … }
suspend fun getRestaurants(address: Address): List<Restaurant> { … }
Suspend modifier
Sync API Usage
fun showUserRestaurants(userId: Long) {
val address = getUserAddress(userId)
val restaurants = getRestaurants(address)
processRestaurants(restaurants)
}
fun getUserAddress(userId: Long): Address { … }
fun getRestaurants(address: Address): List<Restaurant> { … }
Sequential & blocking
fun showUserRestaurants(userId: Long) {
getUserAddress(userId)
.flatMap { address -> getRestaurants(address) }
.subscribe { restaurants -> processRestaurants(restaurants) }
}
Reactive API Usage
fun getUserAddress(userId: Long): Single<Address> { … }
fun getRestaurants(address: Address): Single<List<Restaurant>> { … }
Chained operators
& actions
Kotlin Coroutine API Usage
suspend fun showUserRestaurants(userId: Long) {
val address = getUserAddress(userId)
val restaurants = getRestaurants(address)
processRestaurants(restaurants)
}
suspend fun getUserAddress(userId: Long): Address { … }
suspend fun getRestaurants(address: Address): List<Restaurant> { … }
Suspend modifier
Comparison
suspend fun showUserRestaurants(userId: Long) {
val address = getUserAddress(userId)
val restaurants = getRestaurants(address)
processRestaurants(restaurants)
}
suspend fun getUserAddress(userId: Long): Address { … }
suspend fun getRestaurants(address: Address): List<Restaurant> { … }
fun showUserRestaurants(userId: Long) {
val address = getUserAddress(userId)
val restaurants = getRestaurants(address)
processRestaurants(restaurants)
}
fun getUserAddress(userId: Long): Address { … }
fun getRestaurants(address: Address): List<Restaurant> { … }
Synchronous
Asynchronous
using
Kotlin
Coroutines
Structure of
imperative synchronous code
is the same as
asynchronous code
(taken from KotlinConf 2018 - Exploring Coroutines in Kotlin by Venkat Subramaniam available on
YouTube)
Kotlin Coroutines
Kotlin Coroutines
No restructuring of code to a different paradigm
Reuse existing language control flows
Sequential vs Concurrent execution with coroutines
Complexities of async programming that coroutines handles
Kotlin Coroutines 101
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(1000L)
println("World!")
}
println("Hello")
}
Output:
Hello
World!
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(1000L)
println("World!")
}
println("Hello")
}
Coroutine Builders
Coroutine - an instance
of a suspendable
computation
Kotlin Coroutines 101
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(1000L)
println("World!")
}
println("Hello")
}
Suspending
function suspends
the execution of
the coroutine
Kotlin Coroutines 101
Suspended coroutine
resumes with a
continuation block
public interface Continuation<in T> {
public val context: CoroutineContext
public fun resumeWith(result: Result<T>)
}
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(1000L)
println("World!")
}
println("Hello")
}
Kotlin Coroutines 101
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
doWorld()
}
println("Hello")
}
private suspend fun doWorld() {
delay(1000L)
println("World!")
}
Suspending function is
marked with a
suspend modifier
Kotlin Coroutines 101
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2
org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.2
org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.3.2
Core Library
Integrations
Kotlin Coroutines 101
suspend fun showUserRestaurants(userId: Long) {
val address = getUserAddress(userId)
val restaurants = getRestaurants(address)
processRestaurants(restaurants)
}
Reuse existing Control flows
How can you make the below
method resilient to failures?
suspend fun showUserRestaurants(userId: Long) {
try {
val address = withTimeout(200L) { getUserAddress(userId) }
val restaurants = withTimeout(300L) { getRestaurants(address) }
processRestaurants(restaurants)
} catch (e: TimeoutCancellationException) {
// handle exception here
}
}
Exception handling using
standard try-catch block
Reuse existing Control flows
Sequential vs Concurrent
suspend fun showUserDetails(userId: Long) {
val userInfo = getUserInfo(userId)
val orders = getUserOrders(userId)
combineAndBuild(userInfo, orders)
}
Two independent
calls to
external system
suspend fun getUserInfo(userId: Long): UserInfo { … }
suspend fun getUserOrders(userId: Long): List<Order> { … }
suspend fun showUserDetails(userId: Long) {
val userInfo = getUserInfo(userId)
val orders = getUserOrders(userId)
combineAndBuild(userInfo, orders)
}
Sequential vs Concurrent
suspend fun getUserInfo(userId: Long): UserInfo { … }
suspend fun getUserOrders(userId: Long): List<Order> { … }
first suspension
Sequential vs Concurrent
suspend fun getUserInfo(userId: Long): UserInfo { … }
suspend fun getUserOrders(userId: Long): List<Order> { … }
suspend fun showUserDetails(userId: Long) {
val userInfo = getUserInfo(userId)
val orders = getUserOrders(userId)
combineAndBuild(userInfo, orders)
}
second suspension
Sequential vs Concurrent
suspend fun getUserInfo(userId: Long): UserInfo { … }
suspend fun getUserOrders(userId: Long): List<Order> { … }
suspend fun showUserDetails(userId: Long) {
val userInfo = getUserInfo(userId)
val orders = getUserOrders(userId)
combineAndBuild(userInfo, orders)
}
final call
Sequential vs Concurrent
suspend fun showUserDetails(userId: Long) {
val userInfo = getUserInfo(userId)
val orders = getUserOrders(userId)
combineAndBuild(userInfo, orders)
}
suspend fun getUserInfo(userId: Long): UserInfo { … }
suspend fun getUserOrders(userId: Long): List<Order> { … }
sequential
execution
by default
Sequential vs Concurrent
suspend fun showUserDetails(userId: Long) {
coroutineScope {
val userInfo = async { getUserInfo(userId) }
val orders = async { getUserOrders(userId) }
combineAndBuild(userInfo.await(), orders.await())
}
}
suspend fun getUserInfo(userId: Long): UserInfo { … }
suspend fun getUserOrders(userId: Long): List<Order> { … }
concurrently executed
suspension
happens here
Structured Concurrency
suspend fun showUserDetails(userId: Long) {
coroutineScope {
val userInfo = async { getUserInfo(userId) }
val orders = async { getUserOrders(userId) }
combineAndBuild(userInfo.await(), orders.await())
}
}
When can a resource leakage happen?
Structured Concurrency
suspend fun showUserDetails(userId: Long) {
coroutineScope {
val userInfo = async { getUserInfo(userId) }
val orders = async { getUserOrders(userId) }
combineAndBuild(userInfo.await(), orders.await())
}
}
Exception in a coroutine results in its cancellation
1
2
3
4
Kotlin Coroutines
No restructuring of code to a different paradigm
Reuse existing language control flows
Sequential vs Concurrent execution with coroutines
Complexities of async programming that coroutines handles
Call to Action
https://kotlinlang.org/docs/reference/coroutines-overview.html
https://www.youtube.com/results?search_query=kotlin+coroutines
Give it a try on your next project
Thank You
https://praveergupta.in/
https://praveer09.github.io/

More Related Content

What's hot

Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Roman Elizarov
 
Ruby to Elixir - what's great and what you might miss
Ruby to Elixir - what's great and what you might missRuby to Elixir - what's great and what you might miss
Ruby to Elixir - what's great and what you might missTobias Pfeiffer
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークTsuyoshi Yamamoto
 
Introduction to linux day1
Introduction to linux day1Introduction to linux day1
Introduction to linux day1Gourav Varma
 
Elixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicitElixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicitTobias Pfeiffer
 
Do you Promise?
Do you Promise?Do you Promise?
Do you Promise?jungkees
 
Stop Guessing and Start Measuring - Benchmarking in Practice (Lambdadays)
Stop Guessing and Start Measuring - Benchmarking in Practice (Lambdadays)Stop Guessing and Start Measuring - Benchmarking in Practice (Lambdadays)
Stop Guessing and Start Measuring - Benchmarking in Practice (Lambdadays)Tobias Pfeiffer
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrencyjgrahamc
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practiceGuilherme Garnier
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014Henning Jacobs
 
Python postgre sql a wonderful wedding
Python postgre sql   a wonderful weddingPython postgre sql   a wonderful wedding
Python postgre sql a wonderful weddingStéphane Wirtel
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQAFest
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwiftshark-sea
 
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드NAVER Engineering
 
EventMachine for RubyFuZa 2012
EventMachine for RubyFuZa   2012EventMachine for RubyFuZa   2012
EventMachine for RubyFuZa 2012Christopher Spring
 

What's hot (20)

Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017
 
Golang Channels
Golang ChannelsGolang Channels
Golang Channels
 
Ruby to Elixir - what's great and what you might miss
Ruby to Elixir - what's great and what you might missRuby to Elixir - what's great and what you might miss
Ruby to Elixir - what's great and what you might miss
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
Introduction to linux day1
Introduction to linux day1Introduction to linux day1
Introduction to linux day1
 
Elixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicitElixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicit
 
Clojure入門
Clojure入門Clojure入門
Clojure入門
 
Do you Promise?
Do you Promise?Do you Promise?
Do you Promise?
 
Stop Guessing and Start Measuring - Benchmarking in Practice (Lambdadays)
Stop Guessing and Start Measuring - Benchmarking in Practice (Lambdadays)Stop Guessing and Start Measuring - Benchmarking in Practice (Lambdadays)
Stop Guessing and Start Measuring - Benchmarking in Practice (Lambdadays)
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
 
Cooking pies with Celery
Cooking pies with CeleryCooking pies with Celery
Cooking pies with Celery
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014
 
Python postgre sql a wonderful wedding
Python postgre sql   a wonderful weddingPython postgre sql   a wonderful wedding
Python postgre sql a wonderful wedding
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
 
Combine vs RxSwift
Combine vs RxSwiftCombine vs RxSwift
Combine vs RxSwift
 
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
 
Go破壊
Go破壊Go破壊
Go破壊
 
EventMachine for RubyFuZa 2012
EventMachine for RubyFuZa   2012EventMachine for RubyFuZa   2012
EventMachine for RubyFuZa 2012
 

Similar to Tackling Asynchrony with Kotlin Coroutines

Coroutines in Kotlin. In-depth review
Coroutines in Kotlin. In-depth reviewCoroutines in Kotlin. In-depth review
Coroutines in Kotlin. In-depth reviewDmytro Zaitsev
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.UA Mobile
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationSeven Peaks Speaks
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and InferenceRichard Fox
 
Kotlin - Coroutine
Kotlin - CoroutineKotlin - Coroutine
Kotlin - CoroutineSean Tsai
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
 
Dip into Coroutines - KTUG Munich 202303
Dip into Coroutines - KTUG Munich 202303Dip into Coroutines - KTUG Munich 202303
Dip into Coroutines - KTUG Munich 202303Alex Semin
 
Programação assíncrona utilizando Coroutines
Programação assíncrona utilizando CoroutinesProgramação assíncrona utilizando Coroutines
Programação assíncrona utilizando CoroutinesDiego Gonçalves Santos
 
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, GettLean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, GettDroidConTLV
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor Ivry
 
The Renaissance of C++
The Renaissance of C++The Renaissance of C++
The Renaissance of C++Victor Haydin
 
Programação Assíncrona com Kotlin Coroutines
Programação Assíncrona com Kotlin CoroutinesProgramação Assíncrona com Kotlin Coroutines
Programação Assíncrona com Kotlin CoroutinesLucas Borsatto
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivitynklmish
 
Should it be routine to use coroutines?
Should it be routine to use coroutines?Should it be routine to use coroutines?
Should it be routine to use coroutines?Ion Stefan Brosteanu
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Codemotion
 
pdx-react-observables
pdx-react-observablespdx-react-observables
pdx-react-observablesIan Irvine
 

Similar to Tackling Asynchrony with Kotlin Coroutines (20)

Coroutines in Kotlin. In-depth review
Coroutines in Kotlin. In-depth reviewCoroutines in Kotlin. In-depth review
Coroutines in Kotlin. In-depth review
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android application
 
Current State of Coroutines
Current State of CoroutinesCurrent State of Coroutines
Current State of Coroutines
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
Kotlin - Coroutine
Kotlin - CoroutineKotlin - Coroutine
Kotlin - Coroutine
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
 
Dip into Coroutines - KTUG Munich 202303
Dip into Coroutines - KTUG Munich 202303Dip into Coroutines - KTUG Munich 202303
Dip into Coroutines - KTUG Munich 202303
 
Introdução à Spring Web Flux
Introdução à Spring Web FluxIntrodução à Spring Web Flux
Introdução à Spring Web Flux
 
Programação assíncrona utilizando Coroutines
Programação assíncrona utilizando CoroutinesProgramação assíncrona utilizando Coroutines
Programação assíncrona utilizando Coroutines
 
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, GettLean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
The Renaissance of C++
The Renaissance of C++The Renaissance of C++
The Renaissance of C++
 
Programação Assíncrona com Kotlin Coroutines
Programação Assíncrona com Kotlin CoroutinesProgramação Assíncrona com Kotlin Coroutines
Programação Assíncrona com Kotlin Coroutines
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
 
Should it be routine to use coroutines?
Should it be routine to use coroutines?Should it be routine to use coroutines?
Should it be routine to use coroutines?
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
pdx-react-observables
pdx-react-observablespdx-react-observables
pdx-react-observables
 

More from Tech Triveni

UI Dev in Big data world using open source
UI Dev in Big data world using open sourceUI Dev in Big data world using open source
UI Dev in Big data world using open sourceTech Triveni
 
Why should a Java programmer shifts towards Functional Programming Paradigm
Why should a Java programmer shifts towards Functional Programming ParadigmWhy should a Java programmer shifts towards Functional Programming Paradigm
Why should a Java programmer shifts towards Functional Programming ParadigmTech Triveni
 
Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?Tech Triveni
 
Let’s go reactive with JAVA
Let’s go reactive with JAVALet’s go reactive with JAVA
Let’s go reactive with JAVATech Triveni
 
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
Programmatic Ad Tracking: Let the power of Reactive Microservices do talkingProgrammatic Ad Tracking: Let the power of Reactive Microservices do talking
Programmatic Ad Tracking: Let the power of Reactive Microservices do talkingTech Triveni
 
Let's refine your Scala Code
Let's refine your Scala CodeLet's refine your Scala Code
Let's refine your Scala CodeTech Triveni
 
Supercharged imperative programming with Haskell and Functional Programming
Supercharged imperative programming with Haskell and Functional ProgrammingSupercharged imperative programming with Haskell and Functional Programming
Supercharged imperative programming with Haskell and Functional ProgrammingTech Triveni
 
Observability at scale with Neural Networks: A more proactive approach
Observability at scale with Neural Networks: A more proactive approachObservability at scale with Neural Networks: A more proactive approach
Observability at scale with Neural Networks: A more proactive approachTech Triveni
 
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text DataSemi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text DataTech Triveni
 
Finding the best solution for Image Processing
Finding the best solution for Image ProcessingFinding the best solution for Image Processing
Finding the best solution for Image ProcessingTech Triveni
 
Proximity Targeting at Scale using Big Data Platforms
Proximity Targeting at Scale using Big Data PlatformsProximity Targeting at Scale using Big Data Platforms
Proximity Targeting at Scale using Big Data PlatformsTech Triveni
 
Effecting Pure Change - How anything ever gets done in functional programming...
Effecting Pure Change - How anything ever gets done in functional programming...Effecting Pure Change - How anything ever gets done in functional programming...
Effecting Pure Change - How anything ever gets done in functional programming...Tech Triveni
 
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)Tech Triveni
 
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...Tech Triveni
 
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)Tech Triveni
 
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...Tech Triveni
 
UX in Big Data Analytics - Paramjit Jolly (Guavus)
UX in Big Data Analytics - Paramjit Jolly (Guavus)UX in Big Data Analytics - Paramjit Jolly (Guavus)
UX in Big Data Analytics - Paramjit Jolly (Guavus)Tech Triveni
 
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)Tech Triveni
 
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)Tech Triveni
 
Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...Tech Triveni
 

More from Tech Triveni (20)

UI Dev in Big data world using open source
UI Dev in Big data world using open sourceUI Dev in Big data world using open source
UI Dev in Big data world using open source
 
Why should a Java programmer shifts towards Functional Programming Paradigm
Why should a Java programmer shifts towards Functional Programming ParadigmWhy should a Java programmer shifts towards Functional Programming Paradigm
Why should a Java programmer shifts towards Functional Programming Paradigm
 
Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?
 
Let’s go reactive with JAVA
Let’s go reactive with JAVALet’s go reactive with JAVA
Let’s go reactive with JAVA
 
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
Programmatic Ad Tracking: Let the power of Reactive Microservices do talkingProgrammatic Ad Tracking: Let the power of Reactive Microservices do talking
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
 
Let's refine your Scala Code
Let's refine your Scala CodeLet's refine your Scala Code
Let's refine your Scala Code
 
Supercharged imperative programming with Haskell and Functional Programming
Supercharged imperative programming with Haskell and Functional ProgrammingSupercharged imperative programming with Haskell and Functional Programming
Supercharged imperative programming with Haskell and Functional Programming
 
Observability at scale with Neural Networks: A more proactive approach
Observability at scale with Neural Networks: A more proactive approachObservability at scale with Neural Networks: A more proactive approach
Observability at scale with Neural Networks: A more proactive approach
 
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text DataSemi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text Data
 
Finding the best solution for Image Processing
Finding the best solution for Image ProcessingFinding the best solution for Image Processing
Finding the best solution for Image Processing
 
Proximity Targeting at Scale using Big Data Platforms
Proximity Targeting at Scale using Big Data PlatformsProximity Targeting at Scale using Big Data Platforms
Proximity Targeting at Scale using Big Data Platforms
 
Effecting Pure Change - How anything ever gets done in functional programming...
Effecting Pure Change - How anything ever gets done in functional programming...Effecting Pure Change - How anything ever gets done in functional programming...
Effecting Pure Change - How anything ever gets done in functional programming...
 
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
 
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
 
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
 
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
 
UX in Big Data Analytics - Paramjit Jolly (Guavus)
UX in Big Data Analytics - Paramjit Jolly (Guavus)UX in Big Data Analytics - Paramjit Jolly (Guavus)
UX in Big Data Analytics - Paramjit Jolly (Guavus)
 
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
 
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)
 
Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...
 

Recently uploaded

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Tackling Asynchrony with Kotlin Coroutines

  • 1. Tackling Asynchrony with Kotlin Coroutines Presented By: PRAVEER GUPTA
  • 2. fun getUserAddress(userId: Long): Address { … } fun getRestaurants(address: Address): List<Restaurant> { … } Sync or Async?
  • 3. Reactive approach to Async fun getUserAddress(userId: Long): Single<Address> { … } fun getRestaurants(address: Address): Single<List<Restaurant>> { … } Wrapped return types
  • 4. Kotlin Coroutine’s approach to Async suspend fun getUserAddress(userId: Long): Address { … } suspend fun getRestaurants(address: Address): List<Restaurant> { … } Suspend modifier
  • 5. Sync API Usage fun showUserRestaurants(userId: Long) { val address = getUserAddress(userId) val restaurants = getRestaurants(address) processRestaurants(restaurants) } fun getUserAddress(userId: Long): Address { … } fun getRestaurants(address: Address): List<Restaurant> { … } Sequential & blocking
  • 6. fun showUserRestaurants(userId: Long) { getUserAddress(userId) .flatMap { address -> getRestaurants(address) } .subscribe { restaurants -> processRestaurants(restaurants) } } Reactive API Usage fun getUserAddress(userId: Long): Single<Address> { … } fun getRestaurants(address: Address): Single<List<Restaurant>> { … } Chained operators & actions
  • 7. Kotlin Coroutine API Usage suspend fun showUserRestaurants(userId: Long) { val address = getUserAddress(userId) val restaurants = getRestaurants(address) processRestaurants(restaurants) } suspend fun getUserAddress(userId: Long): Address { … } suspend fun getRestaurants(address: Address): List<Restaurant> { … } Suspend modifier
  • 8. Comparison suspend fun showUserRestaurants(userId: Long) { val address = getUserAddress(userId) val restaurants = getRestaurants(address) processRestaurants(restaurants) } suspend fun getUserAddress(userId: Long): Address { … } suspend fun getRestaurants(address: Address): List<Restaurant> { … } fun showUserRestaurants(userId: Long) { val address = getUserAddress(userId) val restaurants = getRestaurants(address) processRestaurants(restaurants) } fun getUserAddress(userId: Long): Address { … } fun getRestaurants(address: Address): List<Restaurant> { … } Synchronous Asynchronous using Kotlin Coroutines
  • 9. Structure of imperative synchronous code is the same as asynchronous code (taken from KotlinConf 2018 - Exploring Coroutines in Kotlin by Venkat Subramaniam available on YouTube) Kotlin Coroutines
  • 10. Kotlin Coroutines No restructuring of code to a different paradigm Reuse existing language control flows Sequential vs Concurrent execution with coroutines Complexities of async programming that coroutines handles
  • 11. Kotlin Coroutines 101 import kotlinx.coroutines.* fun main() = runBlocking { launch { delay(1000L) println("World!") } println("Hello") } Output: Hello World!
  • 12. import kotlinx.coroutines.* fun main() = runBlocking { launch { delay(1000L) println("World!") } println("Hello") } Coroutine Builders Coroutine - an instance of a suspendable computation Kotlin Coroutines 101
  • 13. import kotlinx.coroutines.* fun main() = runBlocking { launch { delay(1000L) println("World!") } println("Hello") } Suspending function suspends the execution of the coroutine Kotlin Coroutines 101
  • 14. Suspended coroutine resumes with a continuation block public interface Continuation<in T> { public val context: CoroutineContext public fun resumeWith(result: Result<T>) } import kotlinx.coroutines.* fun main() = runBlocking { launch { delay(1000L) println("World!") } println("Hello") } Kotlin Coroutines 101
  • 15. import kotlinx.coroutines.* fun main() = runBlocking { launch { doWorld() } println("Hello") } private suspend fun doWorld() { delay(1000L) println("World!") } Suspending function is marked with a suspend modifier Kotlin Coroutines 101
  • 17. suspend fun showUserRestaurants(userId: Long) { val address = getUserAddress(userId) val restaurants = getRestaurants(address) processRestaurants(restaurants) } Reuse existing Control flows How can you make the below method resilient to failures?
  • 18. suspend fun showUserRestaurants(userId: Long) { try { val address = withTimeout(200L) { getUserAddress(userId) } val restaurants = withTimeout(300L) { getRestaurants(address) } processRestaurants(restaurants) } catch (e: TimeoutCancellationException) { // handle exception here } } Exception handling using standard try-catch block Reuse existing Control flows
  • 19. Sequential vs Concurrent suspend fun showUserDetails(userId: Long) { val userInfo = getUserInfo(userId) val orders = getUserOrders(userId) combineAndBuild(userInfo, orders) } Two independent calls to external system suspend fun getUserInfo(userId: Long): UserInfo { … } suspend fun getUserOrders(userId: Long): List<Order> { … }
  • 20. suspend fun showUserDetails(userId: Long) { val userInfo = getUserInfo(userId) val orders = getUserOrders(userId) combineAndBuild(userInfo, orders) } Sequential vs Concurrent suspend fun getUserInfo(userId: Long): UserInfo { … } suspend fun getUserOrders(userId: Long): List<Order> { … } first suspension
  • 21. Sequential vs Concurrent suspend fun getUserInfo(userId: Long): UserInfo { … } suspend fun getUserOrders(userId: Long): List<Order> { … } suspend fun showUserDetails(userId: Long) { val userInfo = getUserInfo(userId) val orders = getUserOrders(userId) combineAndBuild(userInfo, orders) } second suspension
  • 22. Sequential vs Concurrent suspend fun getUserInfo(userId: Long): UserInfo { … } suspend fun getUserOrders(userId: Long): List<Order> { … } suspend fun showUserDetails(userId: Long) { val userInfo = getUserInfo(userId) val orders = getUserOrders(userId) combineAndBuild(userInfo, orders) } final call
  • 23. Sequential vs Concurrent suspend fun showUserDetails(userId: Long) { val userInfo = getUserInfo(userId) val orders = getUserOrders(userId) combineAndBuild(userInfo, orders) } suspend fun getUserInfo(userId: Long): UserInfo { … } suspend fun getUserOrders(userId: Long): List<Order> { … } sequential execution by default
  • 24. Sequential vs Concurrent suspend fun showUserDetails(userId: Long) { coroutineScope { val userInfo = async { getUserInfo(userId) } val orders = async { getUserOrders(userId) } combineAndBuild(userInfo.await(), orders.await()) } } suspend fun getUserInfo(userId: Long): UserInfo { … } suspend fun getUserOrders(userId: Long): List<Order> { … } concurrently executed suspension happens here
  • 25. Structured Concurrency suspend fun showUserDetails(userId: Long) { coroutineScope { val userInfo = async { getUserInfo(userId) } val orders = async { getUserOrders(userId) } combineAndBuild(userInfo.await(), orders.await()) } } When can a resource leakage happen?
  • 26. Structured Concurrency suspend fun showUserDetails(userId: Long) { coroutineScope { val userInfo = async { getUserInfo(userId) } val orders = async { getUserOrders(userId) } combineAndBuild(userInfo.await(), orders.await()) } } Exception in a coroutine results in its cancellation 1 2 3 4
  • 27. Kotlin Coroutines No restructuring of code to a different paradigm Reuse existing language control flows Sequential vs Concurrent execution with coroutines Complexities of async programming that coroutines handles