95% Don't Understand THIS About Coroutines (Main-Safety)

preview_player
Показать описание
In this video, you'll learn about main-safety, what this means and why it's important to ensure a fluent app experience.

💻 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 4.5h course "The Best Practice Guide to Android Architecture":

Read our weekly Android blog:

Regular programming advice on my Instagram page:

Join my Discord server:
Рекомендации по теме
Комментарии
Автор

The rule Philipp refers to is a convention only. It states that a suspend function should never block the calling thread. If we write the suspend function, then the responsibility is ours to ensure that it is main-safe. If we use a 3rd-party suspend function, then it's the responsibility of that developer to abide by the convention. However, it is still our responsibility to ensure (e.g., read the documentation or study the code) that the 3rd-party suspend function follows the convention. In the case of both Retrofit and Room, their documentation states that any suspend functions they generate will be main-safe.

scottloewke
Автор

Always setting the Dispatcher even though we shouldn't is a code smell. Thanks for awesome content

bitwise-dev
Автор

Thanks Philipp it was very useful. to me you're the most trustworthy person I've ever seen. I can always rely on your content🤘🏻

hamedborna
Автор

Philipp doing what Philipp does, Thanks

princeneo
Автор

withContext just means that everything inside its lambda will be executed in the specified dispatcher, it does no mean that it will magically make the functions called inside of it non-blocking, but it is useful because we can offload the main thread from heavy operations (like an http call or a filesystem operation) and just block a thread on the IO dispatcher instead and then get the result on the calling thread (Main in this case), so it is basically a callback but without the ugliness of it

juanherrera
Автор

Mate I can't explain how much I love your content

GS-wfcp
Автор

I think back in the days when coroutines were released, retrofit still didn't have the main-safety in the functions. So at that point the function in the repository should've have the IO dispatcher. The bad thing is that I understand it just now that I was doing it wrong all these years, just because it started the other way lol

nikolaivasilev
Автор

You should not catch generic exception in the suspend method, such as coroutine may throw `CancellationException` to interrupt invocation

eugenepopovich
Автор

Thank you for your videos Philipp! I always learn something new!

bidbid
Автор

One of the thing to keep in mind is that you should be injecting the dispatcher. That way you can inject test dispatcher while writing unit tests

TravelVideos
Автор

Really useful. Thank you Philipp. Please more videos like this.

johnalejandrogarciaarias
Автор

6:43 "even if it would switch to main dispatcher this would not be a problem" how come?

marianpazdzioch
Автор

Philip woke up and decided to show the facts 😅

BharadwajRavinuthala
Автор

Hey, how does retrofit switch to the background thread? Is there any official source that declares that?

Hmmm
Автор

i've been researching coroutine context for the past 5 days 😮

nesletchimaew
Автор

You can use repeat(5) {} instead of that for

radosawjuszczyk
Автор

interesting contents! It was useful tips. Especially 'suspend function call' icon in Android Studio. Thanks philipp

xemic
Автор

Can you change that yellow lamp to green one 💚

devatrii
Автор

I agree with all the points provided, but what if a repository method does large mapping stuff / CPU work / multiple calls to Room's DAO? Should i wrap a method with withContext(...) or put withContext(...) inside mappers and DAOs?

bigman
Автор

Thank you Philipp, your videos are very valuable to us.🎉

yusuforhan
join shbcf.ru