Be VERY Careful with GlobalScope

  Рет қаралды 13,717

CodingWithMitch

CodingWithMitch

Күн бұрын

The best Android courses in the world: codingwithmitch.com/
There's a few things you should know about Kotlin Coroutines GlobalScope.
This is the default behavior of coroutines that do not use the GlobalScope.
1. If the parent is canceled, all the children are canceled.
2. A parent will always wait for completion of its children.
If a coroutine is launched with the GlobalScope, those two properties no longer hold true.
Instagram: / codingwithmitch
Twitter: / mitch_tabian
.
.
#codingwithmitch

Пікірлер: 55
@BelokonRoman
@BelokonRoman 4 жыл бұрын
Hi, the problem you show in the video is not the problem of the GlobalScope. It is the problem of breaking "structured concurrency". If you replace GlobalScope with any another scope(for instance you can write CoroutineScope(Main).launch instead of GlobalScope.launch) - you will have the same issue. This is because you launch new coroutines on the other scope and break parent-child relation
@GakisStylianos
@GakisStylianos 4 жыл бұрын
You're not my dad. I do what I want 🤣
@codinginflow
@codinginflow 4 жыл бұрын
wow!
@nicolucian6604
@nicolucian6604 2 жыл бұрын
you prolly dont give a shit but does anybody know of a way to get back into an Instagram account?? I stupidly lost the login password. I love any tips you can give me.
@onyxshepard5057
@onyxshepard5057 2 жыл бұрын
@Nico Lucian instablaster =)
@nicolucian6604
@nicolucian6604 2 жыл бұрын
@Onyx Shepard Thanks so much for your reply. I found the site through google and I'm in the hacking process now. Seems to take a while so I will get back to you later with my results.
@andrefilgueiras
@andrefilgueiras 4 жыл бұрын
I was using GlobalScope to send some logs to a server and I saw everybody saying not to use it. Now I know that I was right because this is the perfect example to use it. Thanks Mitch, just like you said, GlobalScope is for analytics.
@sherazali6324
@sherazali6324 4 жыл бұрын
@CodingWithMitch I love the content you create please keep up the good stuff like this.
@BRUHItsABunny
@BRUHItsABunny 4 жыл бұрын
thanks for the demonstration, I wasn't able to find much on this subject a few month ago i guess i will refactor GlobalScope out of my code where needed soon
@j2shoes288
@j2shoes288 4 жыл бұрын
I think you've up'd your game, and giving quality videos. Cheers. ( I've already joined some other course, otherwise, I would join your course ). Maybe I might do so, anyway, this lockdown ( and hence lack of contracting dev roles ) means, I've had time to actually watch some of these videos.
@gamiike
@gamiike 2 жыл бұрын
Thank you Mitch, I was just struggling from handling GlobalScope! Best Regard from Japan
@mohitsinghrawat503
@mohitsinghrawat503 4 жыл бұрын
woow just amazing... never ever got this kind of explanation.. love from India
@irfanirawansukirman4809
@irfanirawansukirman4809 3 жыл бұрын
Thanks mitch 👍
@sifatulhaque6170
@sifatulhaque6170 4 жыл бұрын
I was looking forward to become a founding member but didn’t see any discount. Has the discount promo been removed ?
@JeffTycz
@JeffTycz 4 жыл бұрын
What about doing a video on error handling in coroutines. I would be interested in this topic since it's a little different than you normally would handle exceptions and such
@codingwithmitch
@codingwithmitch 4 жыл бұрын
Yeah that is coming up
@silvahawk
@silvahawk 3 жыл бұрын
I remember in some demo video, you used GlobalScope on a showToast() helper method to run Toast on main thread, is that not the recommended way to call run Toast normally?
@mkpazon_
@mkpazon_ 4 жыл бұрын
The GlobalScope.launch has the same behaviour of declaring a nested CoroutineScope isn't it? CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch { // has no association with parent } }
@fourcade7851
@fourcade7851 4 жыл бұрын
Hi, how are you? Could you please make me lesson on recyclerview about multiselect in JAVA . Thanks beforehand bro
@prakashshukla3558
@prakashshukla3558 4 жыл бұрын
Thumbnail of the month 🏆
@kingsleyetoka2792
@kingsleyetoka2792 4 жыл бұрын
Hello Mitch, Thanks a lot for the videos. Can you make a video on cache invalidation with room or any persistence layer. Am a bit confused on when to fetch new data or use existing data in local cache. Thanks a lot
@codingwithmitch
@codingwithmitch 4 жыл бұрын
Save a timestamp when the data was refreshed. Then after x days refresh it
@bahaaka828
@bahaaka828 4 жыл бұрын
the best use case for GlobalScope is to send the important data (once a specific event occurs) no matter what will happen to the current flow example: Error reporting (the report must be sent in any possible way)
@knoppix20
@knoppix20 4 жыл бұрын
Mitch what model of microphone you use?
@michaelmutinda2567
@michaelmutinda2567 3 жыл бұрын
good job
@bjornk.567
@bjornk.567 3 жыл бұрын
Unfortunately your example is flawed... You could replace both GlobalScope.launch { } calls with CoroutineScope(IO).launch { } calls. The output then is still the same. The reason why it behaves that way is that you actually create a new scope with a new parent here -- whether you use GlobalScope or CoroutineScope.
@charuwaka1
@charuwaka1 4 жыл бұрын
can I use the global scope with delay for this method recyclerView.scrollToPosition(position)?
@codingwithmitch
@codingwithmitch 4 жыл бұрын
You can do whatever you want
@foreverrafs
@foreverrafs 4 жыл бұрын
Hello Mitch, How do you detect when a CoroutineWorker has been cancelled from within the doWork method when the work gets cancelled by the WorkManager
@codingwithmitch
@codingwithmitch 4 жыл бұрын
just add an invokeOnCompletion on the parent job. It will always fire when the job is complete or canceled
@foreverrafs
@foreverrafs 4 жыл бұрын
@@codingwithmitch I'm launching a suspendCoroutine inside the doWork. It doesn't seem to have an invokeOnCompletion method
@omkarpawar1741
@omkarpawar1741 4 жыл бұрын
can you make a video to explain the mess around how can we Access Media files using raw paths in Android R , Android deprecated the Uri - DATA / MediaStore.MediaColumns#DATA in Android Q , They suggested to use "context.getContentResolver.openInputStream(Uri)" instead it will work with Android, but there are various Libraries like FFMPeg and others which require direct file access(there is an issue with pipe protocol. for ffmpeg), which was prohibited, in Android Q, then in Android R the announced raw file paths access fro media paths will be allowed, but there is no documentation for that , there is furter confusion how would this Affect Android Q and the previous versions, its the strangest development around Android , can you please explain
@codingwithmitch
@codingwithmitch 4 жыл бұрын
Files and accessing them on android has always been such a MESS. This is something I've stayed away from. There's so many edge cases and weird "one off" rules. It's not fun and very confusing. Maybe in the future but no plans right now.
@aabhishek4911
@aabhishek4911 4 жыл бұрын
Hi , just out of curiosity , are all of your coroutines videos in a course ? or are you planning something like that ? or they are all independent of each other
@codingwithmitch
@codingwithmitch 4 жыл бұрын
Nah just adding to a youtube playlist
@aabhishek4911
@aabhishek4911 4 жыл бұрын
@@codingwithmitch Great , can i get the link to the playlist :)
@codingwithmitch
@codingwithmitch 4 жыл бұрын
@@aabhishek4911 Look on my channel
@aabhishek4911
@aabhishek4911 4 жыл бұрын
@@codingwithmitch , Thanks , On a different note , in your course Powerful android apps with architecture , are you using data binding ? from the overview it does not look like that , if not using any reason for that ?
@bayraminanc885
@bayraminanc885 4 жыл бұрын
hi, laucn{ ..... } laucn{ ..... } Does this code snipped when running in courotine, is it working sequantially or paralel?
@codingwithmitch
@codingwithmitch 4 жыл бұрын
what
@kgandkg
@kgandkg 4 жыл бұрын
Damn I learnt this today. 🙏. Also be very careful with Fonts.
@codingwithmitch
@codingwithmitch 4 жыл бұрын
My fonts are best fonts
@andy_lamax
@andy_lamax 4 жыл бұрын
Hi, You have good content. But I am sorry to say that GlobalScope.launch is not the same as CoroutineScope(Main).launch(Dispatchers.Default) as stated at 6:23. Yes, the GlobalScope uses the default dispatcher internally, but know that you can even use the GlobalScope to launch coroutines in the main thread. i.e. GlobalScope.launch(Dispatchers.Main). Thats not how structured concurrency works. GlobalScope just means, everything will be launch in the global scope as a child.
@codingwithmitch
@codingwithmitch 4 жыл бұрын
Yes I think the way I said that was confusing. The point I was trying to make was GlobalScope will pull from the same thread pool as Dispatchers.Default. That's all.
@wattheshet
@wattheshet 4 жыл бұрын
just a feedback on your site. Turns out you have to login when choosing to become a member. I tried to become a member as guest did not work. You should do something about that or show a dialog let the want to be member know.
@codingwithmitch
@codingwithmitch 4 жыл бұрын
Always working on the website. Finding the time is difficult.
@wattheshet
@wattheshet 4 жыл бұрын
@@codingwithmitch Focus on that. That's where you get money :D
@tarlamas
@tarlamas 4 жыл бұрын
Neat explanation! GJ GJ= Good Job not GlobalScope Job :P
@oscarperry641
@oscarperry641 4 жыл бұрын
LIKE!
@ChrisAthanas
@ChrisAthanas 3 жыл бұрын
Engagement
@bagadeshkumarr9502
@bagadeshkumarr9502 3 жыл бұрын
Sorry mitch. That is not an issue with global scope. Issue is structured concurrency.
@HienNguyen-xn7tr
@HienNguyen-xn7tr 4 жыл бұрын
now im always careful of globalscope
@gofudgeyourselves9024
@gofudgeyourselves9024 4 жыл бұрын
Hey mithc dont you get bored of doing Android Development daily. Are you exploring new technologies.
@codingwithmitch
@codingwithmitch 4 жыл бұрын
Pretty hard to get bored with android when there is so much stuff constantly. I'm always "looking" at new stuff. But I only dive into things I'm really interested in. Like Python.
@francescomarzo307
@francescomarzo307 4 жыл бұрын
That's the answer at the question everybody wants to know...Lebron, what's your decision? kzbin.info/www/bejne/iIXIdJZun95qfKs
Coroutine Structured Concurrency, Error Handling and Exceptions
18:27
CodingWithMitch
Рет қаралды 19 М.
Supervisor Job (Kotlin Coroutines)
12:05
CodingWithMitch
Рет қаралды 14 М.
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 28 МЛН
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 96 МЛН
PARALLEL Background Tasks with Kotlin Coroutines (ASYNC AND AWAIT)
20:18
Groundbreaking New Solar Energy System - Too Good to be True?
7:07
Sabine Hossenfelder
Рет қаралды 402 М.
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 85 М.
Network Timeouts with Kotlin Coroutines
12:35
CodingWithMitch
Рет қаралды 27 М.
Make Your Code Clean With the SOLID Principles
18:24
Philipp Lackner
Рет қаралды 97 М.
Kotlin Coroutines 101 - Android Conference Talks
24:49
Android Developers
Рет қаралды 133 М.
When RESTful architecture isn't enough...
21:02
Dreams of Code
Рет қаралды 259 М.
LiveData with Coroutines and Flow (Android Dev Summit '19)
18:44
Android Developers
Рет қаралды 110 М.
DO NOT do this in a Software Engineering Interview
7:59
CodingWithMitch
Рет қаралды 9 М.
Let, Also, Apply, Run, With - Kotlin Scope Functions
11:44
Philipp Lackner
Рет қаралды 94 М.
Ноутбук за 20\40\60 тысяч рублей
42:36
Ремонтяш
Рет қаралды 406 М.
Копия iPhone с WildBerries
1:00
Wylsacom
Рет қаралды 8 МЛН
iPhone 15 Pro Max vs IPhone Xs Max  troll face speed test
0:33
Xiaomi SU-7 Max 2024 - Самый быстрый мобильник
32:11
Клубный сервис
Рет қаралды 522 М.