How to avoid 5 common Kotlin Coroutine mistakes

  Рет қаралды 4,739

Lukas Lechner - Advanced Android Development

Lukas Lechner - Advanced Android Development

Күн бұрын

🎓 Get the full 15+ hour-long Course "Kotlin Coroutines and Flow for Android Development" with a nice discount here: www.lukaslechner.com/coroutin...
In this video, I am going to show you 5 of the most common mistakes when using Kotlin Coroutines, so that you don’t make them in your applications.
👨‍🎓 Learn Coroutines and Flow with my Github Example Repository: github.com/LukasLechnerDev/Ko...
TimeStamps:
00:00 - Intro
00:36 - Mistake 1 - Unnecessary Dispatcher Switches
03:36 - Mistake 2 - Not supporting Cancellation
07:59 - Mistake 3 - Using try/catch for exceptions within Coroutines
10:54 - Mistake 4 - Install Coroutine Exception Handler in Child Coroutine
11:36 - Mistake 5 - Accidentally catching CancellationExceptions
15:29 - Full Course "Mastering Kotlin Coroutines for Android Development"
➤ Subscribe to the channel: / @lukaslechner
🌎 Check out my website: www.lukaslechner.com
📬 Subscribe to my newsletter: www.lukaslechner.com/newsletter/
➤ Follow me on twitter: / lukaslechnerdev

Пікірлер: 16
@lukaslechner
@lukaslechner 2 жыл бұрын
🎓 Get the full 9+ hour-long Course "Mastering Kotlin Coroutines for Android Development" with a nice discount here: www.udemy.com/course/coroutines-on-android/?couponCode=30D5A70DBF2D173FC4EB
@Ygormaniz
@Ygormaniz 2 жыл бұрын
Really great video, especially for covering Main-Safety. Most of the content that I read doesn't mention that
@neerajpant4071
@neerajpant4071 2 жыл бұрын
The last one was awesome 😎 we usually use try catch , but in coroutine we should avoid that .use either cancellation or handle exception using cancellation exception
@jess_o
@jess_o 2 жыл бұрын
Great video, thanks for succinct demos and solutions!
@ykalchev
@ykalchev 2 жыл бұрын
Amazing video, very helpful. Thanks mate :)
@BenKadel
@BenKadel Жыл бұрын
Excellent Video! Well done so useful!
@akashkhunt164
@akashkhunt164 2 жыл бұрын
Just a minor thing that in "Mistake 4 - Install Coroutine Exception Handler in Child Coroutine" it is not mandatory to install "exceptionHandler" in both CoroutineScope and parent Coroutine, installing in any one of them will do the job :). Nonetheless great video about all the very common pitfalls (especially the last one)
@rollebonmarquis7574
@rollebonmarquis7574 Жыл бұрын
Maybe it can also be noted that you can have the handler in a child coroutine if this coroutine is a direct child of a supervisor scope and also an explanation as to why does this behave like that but I understand that that much info might cross the boundary of making a video on "common mistakes with coroutines" and enter some other zone. (saying this a layman on this topic) And I agree that the video was great and it was of huge help to me.
@131617
@131617 2 жыл бұрын
👏👏👏
@Alchemist10241
@Alchemist10241 2 жыл бұрын
This video wasn't useful. it was extremely useful. Coroutines are the main part of every Kotlin android project.
@cockyboby
@cockyboby Жыл бұрын
A little bit confusing. You said 6:21 "like delay, withContext..." so you made statement that 'withContext' is also a suspension point which you use in the example, but it isn't cancelled. Why?
@lukaslechner
@lukaslechner Жыл бұрын
withContext will, like delay throw a CancellationException when the Coroutine in which it was called got cancelled and so the Coroutine stops its execution. However this doesn't mean that all code within the withContext block is immediately stopped once the coroutine gets canceled. You need regular suspension points in there so that a CancellationException can be thrown. Does this answer your question?
@DF-ss5ep
@DF-ss5ep 2 жыл бұрын
Are "suspend" functions "suspending functions"? Is that where that keyword comes from? Is it because they can throw CancellationException?
@lukaslechner
@lukaslechner 2 жыл бұрын
I made a video about suspend functions, that should answer your question kzbin.info/www/bejne/mHTEY6iXap14mqc
@JentaroYusong
@JentaroYusong 2 жыл бұрын
Just a little hint. At mistake 3 you're trying to catch a java.lang.Exception but throw a java.lang.Error which is not a subtype of the former. Thus irrespective of the whole suspension, the catch block wouldn't work. Great videos otherwise. :)
@lukaslechner
@lukaslechner 2 жыл бұрын
Oh, you are right! Thanks for the hint!
Best Practices for using Kotlin Coroutines in Android Development
21:35
Lukas Lechner - Advanced Android Development
Рет қаралды 3,4 М.
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 85 М.
Эффект Карбонаро и нестандартная коробка
01:00
История одного вокалиста
Рет қаралды 10 МЛН
How does the .asLiveData() operator work? Kotlin Flow for Android Development
25:01
Lukas Lechner - Advanced Android Development
Рет қаралды 1,4 М.
Untangling Coroutine Testing by Márton Braun
42:49
Kotlin by JetBrains
Рет қаралды 7 М.
Coroutine Structured Concurrency, Error Handling and Exceptions
18:27
CodingWithMitch
Рет қаралды 19 М.
Exception Handling in Kotlin Coroutines EXPLAINED
43:45
Lukas Lechner - Advanced Android Development
Рет қаралды 4,6 М.
95% Don't Understand THIS About Coroutines (Main-Safety)
9:38
Philipp Lackner
Рет қаралды 26 М.
How to handle Backpressure aka BufferOverflows | Kotlin Flow for Android Development
14:31
Lukas Lechner - Advanced Android Development
Рет қаралды 1,3 М.
PARALLEL Background Tasks with Kotlin Coroutines (ASYNC AND AWAIT)
20:18
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 5 МЛН
Лучший браузер!
0:27
Honey Montana
Рет қаралды 286 М.
ВАЖНО! Не проверяйте на своем iPhone после установки на экран!
0:19
ГЛАЗУРЬ СТЕКЛО для iPhone и аксессуары OTU
Рет қаралды 6 МЛН
İĞNE İLE TELEFON TEMİZLEMEK!🤯
0:17
Safak Novruz
Рет қаралды 346 М.