5 Kotlin Coroutine Secrets I Wish I Knew Earlier

preview_player
Показать описание
In this video you'll learn about 5 common mistakes about coroutines that I haven't shared before like that.

💻 Let me be your mentor and become an industry-ready Android developer in 10 weeks:

⭐ Courses with real-life practices
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:

Get my FREE PDF about 20 things you should never do in Jetpack Compose:

Regular programming advice on my Instagram page:

Join my Discord server:

00:00 - Introduction
00:29 - Secret 1
04:01 - Secret 2
08:27 - Secret 3
14:11 - Secret 4
19:15 - Secret 5
Рекомендации по теме
Комментарии
Автор

For secret #3, I think another option if you really need to catch general exceptions could be to catch CancellationException in its own, dedicated catch block to rethrow it. Not much different, but I like the clarity of using separate catch blocks for each type of exception that can be caught

laurent.treguier
Автор

Ive 7 years of experience in Android app dev, But I never paid any attention to these! Thank you so much!

yurowitz
Автор

Please never ever ever ever copy anything byte by byte. You made the function as inefficient as possible. Copy single byte then do ensureActive and your file is copying like 1000 times slower? Always use buffers so such operations start with 4 kb buffer and measure, experiment. But please, never do byte by byte...

jakosss
Автор

For #4, in case of Dagger, you could use qualifier, and inject Dispatcher directly. Or without DI, simply set it to some default value.

erTurbo
Автор

I have to go check my app for 2 & 3.
Thank you. I love learning about Coroutines

AbdulelahAGR
Автор

note about 5 example, if you read/write data byte-by-byte it could be very slow...

DenisKor
Автор

When I see hardcoded dispatchers in the code, it's usually a sign that people don't care about testing functionality with coroutines in general 🙂

olgaderyabina
Автор

Hi Philipp. I would like to tell you how much your videos like this one helped me in the recent past and I'm very grateful to you because of it. Also I'd like to give you something back: for Secret 1 there is actually a Service implementation that has a built in lifecycle and lifecycleScope just like a viewModel has and it's called LifecycleService.

RbJ
Автор

Hey Philipp,

Thanks for the video! Could you please make a new video on "How to use Room with KMP"? Previously, your video covered only Android and iOS, but I would like to see how this can be done for desktop as well.

Also, it would be great if you could create a full 3-4 hour production ready project based on KMP that runs on Android, iOS, and desktop.

Thanks!

mr.suryansh
Автор

You can use isActive in your while loop that will solve the problem isn't it ? 14:44

govindyadav
Автор

I agree with everything you've read, colleague

FilipAdam-vu
Автор

On tip 3, you can have the exception handling outside the loop (if you want the behaviour of cancelling the loop) i.e. try { while {} }catch {}. This advice may not be pertinent to every exception, but swallowing general exceptions in a loop is rarely advisable.

TheAndreArtus
Автор

I knew about supervisor, it is used also in viewmodelScope

atlas
Автор

I think I've made one mistake relating to secret number 2 (Supervisor Job) in my last project. I have a bug (not a crasher) in the app but it happens rarely.

Alchemist
Автор

What if in #3 we do not re-throw, but replace while (true) with while (isActive)?

Radiokot
Автор

Fifth solution is not a solution,
But new problem

TechCocoon
Автор

Hi please help me i want to do work in kotlin not jetpack. I want to do data transfer using local only hotspot is that possible

bijithbiju
Автор

Facts about Kotlin that annoy me:
- They added null safety. But removed exceptions safety.
- They could have built a cancellation mechanism into the generated code. But they invented CancellationException.

smallbig
Автор

Secret 5 is going to destroy the performance though ...

PhpXp
Автор

Wow can I use it in multiplatform kmp or not?

meshoraouf