KEMBAR78
A Journey From Callback Hell To Kotlin Coroutines | PPTX
A Journey from
Callback Hell
to
Kotlin Coroutines
Ahmed Nabil
Kotlin Egypt
@AhmedNMahran
Sat. Jan 1 2022
About Me
About Me
1. Writing Code since I was 11
2. 8+ years in Mobile App development
3. Given talks to thousands of audiences
4. Prev. Android Mentor at 1M Arab Coders.
5. Worked at Hungerstation,Codly, and others.
6. Software Tech. Lead at Vodafone (_VOIS).
7. Head of Kotlin Egypt.
About Me
About Me
What
is Kotlin ?
1. A modern Programming Language.
2. Developed by Jetbrains & Open-Source community
3. Since 2010.
4. Current Stable Version is 1.6.10 (as of 31-12-2021)
Kotlin
1. Multiplatform-Mobile
2. Server-Side
3. Web Front-End
4. Android
5. WatchOS
6. Data Science
7. and more
Used to Develop
About Me
Let
the journey
Begin
ANR
● any operation > 16ms may cause Lag
● I/O operations, long running operation
● Main thread should ONLY do
UI operations
About Me
Asynchronous
Code
1.Threading
2.Callbacks
3.Futures, Promises
4.Reactive Extensions (Rx)
5.Coroutines
Approaches
About Me
Problem
Code running in Main
thread causing Crash or
Lag.
About Me
Threads
A program splits itself
into 2 or more running
tasks
1.Expensive
2.Not Infinite, limited with device capabilities
3.Not always available, (e.g. JS doesn’t have threading)
4.Hard to Error-handle and debug
Threads Limitations
About Me
Callbacks
a function sent as an
argument to another
function to be executed
at certain point in time.
1.Nested Callbacks not easy to understand
2.Hard to Error-handle and debug
Callback Limitations
About Me
Futures
and Promises
I promise I’ll return at
some point in the future.
1.Nested Callbacks not easy to understand
2.Return Type :
Needs changing the models (extra steps in getting the data)
3.Hard to Error-handle and debug
Limitations
About Me
Rx
Everything is a stream
and it’s observable
Needs learning new apis
:(
About Me
Coroutines
Kotlin’s approach to work
with async. code
Process
Thread1
Thread2
Coroutine1
Coroutine2
Coroutine3
Couroutine4
1.No new apis needed, same language used (kotlin)
2.Return type doesn’t change.
3.Write sequential code while being thread-safe
4.Lightweight, can run many of them in one thread,
5.Easy to switch between threads
6.Platform independent
7.Easy to debug and detect errors.
Coroutines
Quiz
& Prize
About Me
Follow Me
@AhmedNMahran
Thanks!
Twitter Youtube Linkedin Medium Github
Thanks
Ahmed Nabil
Kotlin Egypt
@AhmedNMahran

A Journey From Callback Hell To Kotlin Coroutines