Sometimes I run into this issue because I launched to meany heavy tasks as coroutines inside the main thread. Had to refactor the code again to fix it..
@@codingwithmitch Meanwhile, other people out there using coroutines to do some crazy shit with views. ( medium.com/androiddevelopers/suspending-over-views-19de9ebd7020 )
@@GakisStylianos I complete agree with you on that point. Sometime those medium articles are so complicated that it right away makes me want to stop learning altogether.
@@codingwithmitch The reason you shouldn't use GlobalScope is because of structured concurrency, to make sure all your asynchronous tasks are completed (or cancelled) before the application moves on. Creating a `CoroutineScope` without cancelling it or waiting for it, is equally as bad using `GlobalScope` (I sadly see this very often). In fact I could argue it is worse, since you may not know that it is not safe. I think it's important to address this in your video.
The dispatcher defines what pool of threads the coroutine will start in. In the case of the MAIN dispatcher though, there is only one thread. The main thread.
Coroutines are implementing their own "event loop", and when delay function called, it will resume coroutine through this time by event, so there's no magic here)
#Best_channel Thanks never enough for you :) when I use GlobalScope it never freeze my app. what the difference between CoroutineScope & GlobalScope? what do you recommend for use?
Loved the example chosen and how clearly it demonstrates the concept. The aha moment was how a Coroutines Job is different from a Thread. Also see the very first video in this series ruclips.net/video/F63mhZk-1-Y/видео.html. But damn that font is freezing my 🧠 thread.
Hmmm the title of this video is almost like clickbait! You would never run a network request on the main thread. You would specify Dispatchers.IO in your child launch. It's an interesting "article" but your title and aim ruined it.
@@codingwithmitch As someone newer to the Android world, I have directly been introduced to Coroutines so it's the only thing I know. And that awesome. However, what I fear is that when I start working in a company I will basically be fucked. I know they are using Java still, so RX most likely is there. I hope the knowledge translates backwards as well, as in I hope it's easier for me to jump into RX after understanding Coroutines a bit.
@@codingwithmitch This is a really awkward time then. Because for now, we will need to learn enough to work with the older projects, but it won't be that fun since in the near future it may not be that relevant anymore.
Basically you are explaining that coroutines won't run if you stress out your CPU. This also counts for threads and is so pointless to make a video about to be honest...
Just reading about co routines and had a doubt about the freezing the main UI and I come to RUclips to see your other videos and u upload this xD
Good timing
Sometimes I run into this issue because I launched to meany heavy tasks as coroutines inside the main thread. Had to refactor the code again to fix it..
will it help unfreeze it if i left it by my heater?
Excellent video, regards from Caracas, Venezuela
Thankyou mitch for this informative video..
Mitch, could you tell me what suspend function does? I googled it a lot but I still can't understand
It just means it must be executed in a coroutine. And it "suspends" the coroutine until complete
tl;dr: Coroutines are not magic. You still need to use your brain.
But some do not has gud brain
@@codingwithmitch Meanwhile, other people out there using coroutines to do some crazy shit with views. ( medium.com/androiddevelopers/suspending-over-views-19de9ebd7020 )
@@GakisStylianos Jesus that looks complicated
@@codingwithmitch I know right. Every time I browse what other people do on Medium I just feel more dumb instead of learning hahahaha
@@GakisStylianos I complete agree with you on that point. Sometime those medium articles are so complicated that it right away makes me want to stop learning altogether.
Can you help in doing budge count with textview especially in messaging.
Use Data -Binding
Why do you do `CoroutineScope(Main).launch { ... }` instead of `GlobalScope.launch(Main) { ... }`? It's an extra allocation you don't need.
I'll make a video today about GlobalScope and why you shouldn't use it. Probably ever.
@@codingwithmitch The reason you shouldn't use GlobalScope is because of structured concurrency, to make sure all your asynchronous tasks are completed (or cancelled) before the application moves on.
Creating a `CoroutineScope` without cancelling it or waiting for it, is equally as bad using `GlobalScope` (I sadly see this very often). In fact I could argue it is worse, since you may not know that it is not safe.
I think it's important to address this in your video.
Thanks Mitch for the video
What if the child job has been canceled but still its running due to heavy long running execution?
Please make a video on only network request using coroutine
Just create a retrofit request that returns a suspend function. Done
But what happens when i launch the Coroutine only 90000 times?
Thanks for the video .. Am i alone thought the title is Corona or Coroutine .... 😷
no you are not alone
With 200k printlns I think it would've frozen even without launching additional coroutines
Awesome! Thank you
So two coroutines running on different dispatchers run in the same thread? Or does the dispatcher define what thread they run in?
The dispatcher defines what pool of threads the coroutine will start in. In the case of the MAIN dispatcher though, there is only one thread. The main thread.
I thought println doesn't work on Android 🧐
that was so helful thanks
Extremely useful. Thanks
keep it up!
After seeing main function, I got a little nervous thinking what the entry point is doing here. Tricky moment.
Coroutines are implementing their own "event loop", and when delay function called, it will resume coroutine through this time by event, so there's no magic here)
Thank you sir
#Best_channel
Thanks never enough for you :)
when I use GlobalScope it never freeze my app.
what the difference between CoroutineScope & GlobalScope? what do you recommend for use?
Loved the example chosen and how clearly it demonstrates the concept. The aha moment was how a Coroutines Job is different from a Thread. Also see the very first video in this series ruclips.net/video/F63mhZk-1-Y/видео.html.
But damn that font is freezing my 🧠 thread.
Wow, that's interesting, but what if we launched a coroutine using runblocking on the main dispatcher would that block the main thread?
Yes
publishing a video today about that actually
wow i didnt know i can freeze the u i!!
Title should be "will delay() FREEZE your UI"
Hmmm the title of this video is almost like clickbait! You would never run a network request on the main thread. You would specify Dispatchers.IO in your child launch. It's an interesting "article" but your title and aim ruined it.
Yes I know. It's a demonstration to conceptualize how coroutines work
bye bye RXXXXXXXXXXXXX?
I would say so
@@codingwithmitch As someone newer to the Android world, I have directly been introduced to Coroutines so it's the only thing I know. And that awesome.
However, what I fear is that when I start working in a company I will basically be fucked. I know they are using Java still, so RX most likely is there.
I hope the knowledge translates backwards as well, as in I hope it's easier for me to jump into RX after understanding Coroutines a bit.
Also never touched RX!
@@GakisStylianos my guess is Rx will get phased out.
@@codingwithmitch This is a really awkward time then. Because for now, we will need to learn enough to work with the older projects, but it won't be that fun since in the near future it may not be that relevant anymore.
Basically you are explaining that coroutines won't run if you stress out your CPU. This also counts for threads and is so pointless to make a video about to be honest...