SlideShare a Scribd company logo
1 of 19
Download to read offline
KOTLIN
COROUTINES
in Android
2018 / KOTLIN COROUTINES IN ANDROID
COROUTINES
Async
easy
Coroutines provide a way to
avoid blocking a thread and
simplify asynchronous
programming
SLIDE HEADLINE / Kotlin Coroutines in Android
COROUTINES
SLIDE HEADLINE / Kotlin Coroutines in Android
Blocking vs
Suspending
Coroutines are computations
that can be suspended without
blocking a thread
Suspending
2018 / KOTLIN COROUTINES IN ANDROID
COROUTINES
SLIDE HEADLINE / Kotlin Coroutines in Android
Launch
launch { … } is a Kotlin regular
function, which takes
suspending block and returns a
Job instance
Suspending
Launch
2018 / KOTLIN COROUTINES IN ANDROID
COROUTINES
SLIDE HEADLINE / Kotlin Coroutines in Android
Async
Await
async { … } in Kotlin is regular
function with suspending
parameter
await() is a method to get value
from suspending function done
asynchronous
Suspending
Launch
Async / await
2018 / KOTLIN COROUTINES IN ANDROID
Network
request
We want to send a request to
get some information …
fun getLocation(): Location {
/// gets current location
return location
}
2018 / KOTLIN COROUTINES IN ANDROID
Network
request
… and some more information
based on previous ...
fun getLocation(): Location { … }
fun getWeather(location: Location): Weather {
/// gets weather for current location
return weather
}
2018 / KOTLIN COROUTINES IN ANDROID
Network
request
… and show the result
fun getLocation(): Location { … }
fun getWeather(location: Location): Weather { … }
fun showWeather(weather: Weather) {
/// shows weather on the screen
}
2018 / KOTLIN COROUTINES IN ANDROID
fun getLocationAsync(cb: (Location) -> Unit) {
/// gets current location and returns it
/// with callback when done
}
Callbacks
We can do same with callbacks
2018 / KOTLIN COROUTINES IN ANDROID
fun getLocationAsync(cb: (Location) -> Unit) { … }
fun getWeatherAsync(location: Location,
cb: (Weather) -> Unit) {
/// gets weather for current location async
}
Callbacks
We can do same with callbacks
2018 / KOTLIN COROUTINES IN ANDROID
fun getLocationAsync(cb: (Location) -> Unit) { … }
fun getWeatherAsync(location: Location,
cb: (Weather) -> Unit) { … }
fun showWeather(weather: Weather) {
/// shows weather on the screen
}
Callbacks
We can do same with callbacks
2018 / KOTLIN COROUTINES IN ANDROID
fun getLocationAsync(cb: (Location) -> Unit) { … }
fun getWeatherAsync(location: Location,
cb: (Weather) -> Unit) { … }
fun showWeather(weather: Weather) { … }
fun processWeather() {
getLocationAsync { location ->
getWeatherAsync { weather ->
showWeather(weather)
}
}
}
Callbacks
We can do same with callbacks
2018 / KOTLIN COROUTINES IN ANDROID
Suspending
function
Suspending function suspends
the coroutine, without blocking
the thread
suspend fun getLocation(): Location {
/// gets current location & suspends
return location
}
2018 / KOTLIN COROUTINES IN ANDROID
Suspending
function
Suspending function suspends
the coroutine, without blocking
the thread
suspend fun getLocation(): Location { … }
suspend fun getWeather(location: Location): Weather {
/// gets weather for current location &
/// suspends
return weather
}
2018 / KOTLIN COROUTINES IN ANDROID
Suspending
function
Suspending function suspends
the coroutine, without blocking
the thread
2018 / KOTLIN COROUTINES IN ANDROID
suspend fun getLocation(): Location { … }
suspend fun getWeather(location: Location)
: Weather { … }
fun showWeather(weather: Weather) {
/// shows weather on the screen
}
suspend fun processWeather() {
val location = getLocation()
val weather = getWeather(location)
showWeather(weather)
}
2018 / KOTLIN COROUTINES IN ANDROID
Launch
coroutine
/** Simple countdown with coroutines */
fun countdown(start: Int) {
launch(UI) {
for (i in start downTo 0) {
/// show time
delay(1000)
}
}
}
2018 / KOTLIN COROUTINES IN ANDROID
Place your screenshot
here
2018 / KOTLIN COROUTINES IN ANDROID
Thanks!
Any questions?
You can find me at
me@robertlevonyan.com
Or tweet
@robertlevonyan

More Related Content

What's hot

Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
Finally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersFinally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersRudy De Busscher
 
Testando API REST - Parte 1
Testando API REST - Parte 1Testando API REST - Parte 1
Testando API REST - Parte 1alinebiath
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with MockitoRichard Paul
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Assespro pr-workshop-robot framework
Assespro pr-workshop-robot frameworkAssespro pr-workshop-robot framework
Assespro pr-workshop-robot frameworkMayara Fernandes
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGSiddharth Sharma
 
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
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Simplilearn
 
Kotlin coroutine - behind the scenes
Kotlin coroutine - behind the scenesKotlin coroutine - behind the scenes
Kotlin coroutine - behind the scenesAnh Vu
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation MobileAcademy
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in KotlinAlexey Soshin
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 

What's hot (20)

Postman.ppt
Postman.pptPostman.ppt
Postman.ppt
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Test api
Test apiTest api
Test api
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Finally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersFinally, easy integration testing with Testcontainers
Finally, easy integration testing with Testcontainers
 
The Xtext Grammar Language
The Xtext Grammar LanguageThe Xtext Grammar Language
The Xtext Grammar Language
 
Testando API REST - Parte 1
Testando API REST - Parte 1Testando API REST - Parte 1
Testando API REST - Parte 1
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Assespro pr-workshop-robot framework
Assespro pr-workshop-robot frameworkAssespro pr-workshop-robot framework
Assespro pr-workshop-robot framework
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNG
 
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
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022
 
Kotlin coroutine - behind the scenes
Kotlin coroutine - behind the scenesKotlin coroutine - behind the scenes
Kotlin coroutine - behind the scenes
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
.Net Core
.Net Core.Net Core
.Net Core
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 

Similar to Kotlin coroutines

droidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutinesdroidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin CoroutinesArthur Nagy
 
JavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfJavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfAnton Arhipov
 
Compose로 Android:Desktop 멀티플랫폼 만들기.pdf
Compose로 Android:Desktop 멀티플랫폼 만들기.pdfCompose로 Android:Desktop 멀티플랫폼 만들기.pdf
Compose로 Android:Desktop 멀티플랫폼 만들기.pdfssuserb6c2641
 
Android Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondAndroid Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondRamon Ribeiro Rabello
 
GDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDGKuwaitGoogleDevel
 
Structured concurrency with Kotlin Coroutines
Structured concurrency with Kotlin CoroutinesStructured concurrency with Kotlin Coroutines
Structured concurrency with Kotlin CoroutinesVadims Savjolovs
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlinAdit Lal
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android developmentAdit Lal
 
Native Payment - Part 1.pdf
Native Payment - Part 1.pdfNative Payment - Part 1.pdf
Native Payment - Part 1.pdfShaiAlmog1
 
Reducing boilerplate with Kotlin, KTX and Kotlin Android Extensions
Reducing boilerplate with Kotlin, KTX and Kotlin Android ExtensionsReducing boilerplate with Kotlin, KTX and Kotlin Android Extensions
Reducing boilerplate with Kotlin, KTX and Kotlin Android ExtensionsPatrick Steiger
 
Creating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdfCreating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdfShaiAlmog1
 
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsugFrom Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsugToshiaki Maki
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Omar Miatello
 
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlowAll Things Open
 
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlowSpinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlowPaulBrebner2
 
Building a p2 update site using Buckminster
Building a p2 update site using BuckminsterBuilding a p2 update site using Buckminster
Building a p2 update site using Buckminsterguest5e2b6b
 

Similar to Kotlin coroutines (20)

droidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutinesdroidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutines
 
JavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfJavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdf
 
Compose로 Android:Desktop 멀티플랫폼 만들기.pdf
Compose로 Android:Desktop 멀티플랫폼 만들기.pdfCompose로 Android:Desktop 멀티플랫폼 만들기.pdf
Compose로 Android:Desktop 멀티플랫폼 만들기.pdf
 
QCon São Paulo 2018
QCon São Paulo 2018QCon São Paulo 2018
QCon São Paulo 2018
 
Angular mix chrisnoring
Angular mix chrisnoringAngular mix chrisnoring
Angular mix chrisnoring
 
Android Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondAndroid Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyond
 
GDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDG Kuwait - Modern android development
GDG Kuwait - Modern android development
 
Structured concurrency with Kotlin Coroutines
Structured concurrency with Kotlin CoroutinesStructured concurrency with Kotlin Coroutines
Structured concurrency with Kotlin Coroutines
 
Iphone course 2
Iphone course 2Iphone course 2
Iphone course 2
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlin
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android development
 
Native Payment - Part 1.pdf
Native Payment - Part 1.pdfNative Payment - Part 1.pdf
Native Payment - Part 1.pdf
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
Reducing boilerplate with Kotlin, KTX and Kotlin Android Extensions
Reducing boilerplate with Kotlin, KTX and Kotlin Android ExtensionsReducing boilerplate with Kotlin, KTX and Kotlin Android Extensions
Reducing boilerplate with Kotlin, KTX and Kotlin Android Extensions
 
Creating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdfCreating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdf
 
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsugFrom Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
 
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlowSpinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 
Building a p2 update site using Buckminster
Building a p2 update site using BuckminsterBuilding a p2 update site using Buckminster
Building a p2 update site using Buckminster
 

Recently uploaded

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 

Recently uploaded (20)

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 

Kotlin coroutines

  • 2. 2018 / KOTLIN COROUTINES IN ANDROID COROUTINES Async easy Coroutines provide a way to avoid blocking a thread and simplify asynchronous programming SLIDE HEADLINE / Kotlin Coroutines in Android
  • 3. COROUTINES SLIDE HEADLINE / Kotlin Coroutines in Android Blocking vs Suspending Coroutines are computations that can be suspended without blocking a thread Suspending 2018 / KOTLIN COROUTINES IN ANDROID
  • 4. COROUTINES SLIDE HEADLINE / Kotlin Coroutines in Android Launch launch { … } is a Kotlin regular function, which takes suspending block and returns a Job instance Suspending Launch 2018 / KOTLIN COROUTINES IN ANDROID
  • 5. COROUTINES SLIDE HEADLINE / Kotlin Coroutines in Android Async Await async { … } in Kotlin is regular function with suspending parameter await() is a method to get value from suspending function done asynchronous Suspending Launch Async / await 2018 / KOTLIN COROUTINES IN ANDROID
  • 6. Network request We want to send a request to get some information … fun getLocation(): Location { /// gets current location return location } 2018 / KOTLIN COROUTINES IN ANDROID
  • 7. Network request … and some more information based on previous ... fun getLocation(): Location { … } fun getWeather(location: Location): Weather { /// gets weather for current location return weather } 2018 / KOTLIN COROUTINES IN ANDROID
  • 8. Network request … and show the result fun getLocation(): Location { … } fun getWeather(location: Location): Weather { … } fun showWeather(weather: Weather) { /// shows weather on the screen } 2018 / KOTLIN COROUTINES IN ANDROID
  • 9. fun getLocationAsync(cb: (Location) -> Unit) { /// gets current location and returns it /// with callback when done } Callbacks We can do same with callbacks 2018 / KOTLIN COROUTINES IN ANDROID
  • 10. fun getLocationAsync(cb: (Location) -> Unit) { … } fun getWeatherAsync(location: Location, cb: (Weather) -> Unit) { /// gets weather for current location async } Callbacks We can do same with callbacks 2018 / KOTLIN COROUTINES IN ANDROID
  • 11. fun getLocationAsync(cb: (Location) -> Unit) { … } fun getWeatherAsync(location: Location, cb: (Weather) -> Unit) { … } fun showWeather(weather: Weather) { /// shows weather on the screen } Callbacks We can do same with callbacks 2018 / KOTLIN COROUTINES IN ANDROID
  • 12. fun getLocationAsync(cb: (Location) -> Unit) { … } fun getWeatherAsync(location: Location, cb: (Weather) -> Unit) { … } fun showWeather(weather: Weather) { … } fun processWeather() { getLocationAsync { location -> getWeatherAsync { weather -> showWeather(weather) } } } Callbacks We can do same with callbacks 2018 / KOTLIN COROUTINES IN ANDROID
  • 13. Suspending function Suspending function suspends the coroutine, without blocking the thread suspend fun getLocation(): Location { /// gets current location & suspends return location } 2018 / KOTLIN COROUTINES IN ANDROID
  • 14. Suspending function Suspending function suspends the coroutine, without blocking the thread suspend fun getLocation(): Location { … } suspend fun getWeather(location: Location): Weather { /// gets weather for current location & /// suspends return weather } 2018 / KOTLIN COROUTINES IN ANDROID
  • 15. Suspending function Suspending function suspends the coroutine, without blocking the thread 2018 / KOTLIN COROUTINES IN ANDROID suspend fun getLocation(): Location { … } suspend fun getWeather(location: Location) : Weather { … } fun showWeather(weather: Weather) { /// shows weather on the screen } suspend fun processWeather() { val location = getLocation() val weather = getWeather(location) showWeather(weather) }
  • 16. 2018 / KOTLIN COROUTINES IN ANDROID
  • 17. Launch coroutine /** Simple countdown with coroutines */ fun countdown(start: Int) { launch(UI) { for (i in start downTo 0) { /// show time delay(1000) } } } 2018 / KOTLIN COROUTINES IN ANDROID
  • 18. Place your screenshot here 2018 / KOTLIN COROUTINES IN ANDROID
  • 19. Thanks! Any questions? You can find me at me@robertlevonyan.com Or tweet @robertlevonyan