Raka Adi Nugroho
Software Engineer @Tokopedia
Kadang nongkrong di
www.blogtoandroid.com
github.com/rakaadinugroho
medium.com/rakaadinugroho
Slide 3
Slide 3 text
Say Hello to Coroutine
What is that
Why Coroutine?
What can Coroutine Do?
Agenda
Coroutine met Retrofit
Slide 4
Slide 4 text
Coroutine Basic Usage
Feel Code with Coroutine
Goals
Explore more about
Coroutine
Slide 5
Slide 5 text
Lagging?
Slide 6
Slide 6 text
Lagging?
oh no!
Slide 7
Slide 7 text
Asynchrony
refers to the occurrence of events independent of the main program flow and
ways to deal with such events - wikipedia
Slide 8
Slide 8 text
On Android
Slide 9
Slide 9 text
On Android
Slide 10
Slide 10 text
Google developers highly recommend using Kotlin
Coroutines for doing asynchronous work and when
integrating Jetpack.
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
Coroutine?
A coroutine is a concurrency design pattern
that you can use on Android to simplify code
that executes asynchronously.
Slide 13
Slide 13 text
Coroutine?
The Kotlin team defines coroutines as “lightweight threads”
Coroutines similar to Threads
Coroutine #1 Coroutine #N
Thread
Slide 14
Slide 14 text
Concurrency?Parallel?
Slide 15
Slide 15 text
Concurrency? Parallel?
Slide 16
Slide 16 text
Concurrency? Parallel?
Concurrency is Structure | Parallel is execution
Slide 17
Slide 17 text
Suspending
Coroutine #1
Thread
Backbone of Coroutine
Slide 18
Slide 18 text
Suspending
Slide 19
Slide 19 text
Job
Cancellable
has Lifecycle
Destroy(s) when Complete
Deffered
Implement Job
await() to get Result
Coroutine Job
Slide 20
Slide 20 text
launch
fire forget
return as Job
async
fire giving result
return as Deffered
runBlocking
Blocks current Thread
Coroutine
Builder
Slide 21
Slide 21 text
1
2
3
Slide 22
Slide 22 text
1
2
3
Slide 23
Slide 23 text
1
2
3
Slide 24
Slide 24 text
Solve 2 Primary Problem
Manage long-running tasks that might otherwise block the main thread and cause your
app to freeze.
Providing main-safety, or safely calling network or disk operations from the main thread.
Slide 25
Slide 25 text
Solve 2 Primary Problem
Manage long-running tasks that might otherwise block the main thread and cause your
app to freeze.
Providing main-safety, or safely calling network or disk operations from the main thread.