Thanks for the video! I was watching another video of yours about memory leaking, and I think would be interesting to join these concepts into one video: like an example of memory leaking with coroutines.. Best practices to avoid it, etc..
Great tutorials, very helpful and descriptive. Loved the part where u corrected ur self with “technically they won’t run at the same time” . Your attention to details is really commendable. Good stuff mate 👌
Hi Mitch , If we are using CoroutineScope(IO).launch{ } as parent scope for our child scope then if one fails then other won't be working right? In such case how can we execute Parellel?
When to use async await and when to use Launch-> Async Await -> If you want to wait to update UI after finishing all coroutines, (even all coroutines are executing parallel) go for async-await. Launch-> All parallel executions are updating UI after finishing their execution. This is my understanding of both of these functionalities. @codingWithMitch
I appreciate a lot thanks.Great work !!! I found less videos on handling exception while making api calls using coroutine. I found sometime please update us on exception handling.
Sir, I'm watching your good videos for already a long time now and I only wanted to say that I think maybe it would be better for people learning this if you could be a litle bit slower. Since you understand all the topics so well you are so fast and sometimes it gets difficult to follow. Thanks!
If you switched the order on those awaits, both would wait until job2 finished before setting text, right? Since the first set text would await job2 before moving on to the second await?
Returning values from asynchronous callback listeners? So i have an example (in Java from API documentation, but i work in Kotlin personally) What's a good way to return values from the onSuccess or onError callback methods here? Currently i am using MutableLiveData and LiveData and then observing a DataState like value and doing something on that. BUT is there a better way or cleaner way to handle returning a value from onSuccess/onError? Oh yeah i went to create this method in a service or repository and call it from a ViewModel. sessionClient.authorizedRequest(uri, properties, postParameters, HttpConnection.RequestMethod.POST, new RequestCallback() { @Override public void onSuccess(@NonNull JSONObject result) { //handle JSONObject result. } @Override public void onError(String error, AuthorizationException exception) { //handle error } });
Just got confused, Using the launch if the 2 jobs are running parallel then the overall time taken should be Job2's time right ? since it running in parallel Job 1 should have completed before Job2. Please correct me if my understanding is wrong.
Hi @CodingWithMitch , I have a doubt. , Why Job1 and Job2 are running on different thread . When they are fired in same scope of coroutine . As you said Coroutine are not threads they are like job which perform on same thread .
Hi Mitch, is it possible to create a timer app using Kotlin with very high accuracy? i tried but its not accurate when i put delay of 1000 ms and very inaccurate when i put delay of 100 ms
I think the two jobs are in same IO scope and will run on same thread that is why the name of the thread is same.But i'm confused why async was having different thread names , I have tried it on my device they ran on same thread.
There is no hard limit. But I'm sure it's possible to reach a limit. It would depend on how heavy the work you were doing was. The limitation would be on the device hardware not the software
Run two loops, one that prints "1" other one that prints "2". If log is 1111122222 than they don't run in parallel and if log is 1212121212 (for example, the thing is that 1 and 2 intertwine) than they are working in parallel.
@@markonovakovic3838 yeah, sure, i was just expecting the same 121212... pattern when i first ran paralell coroutines. and i got 111222111111222221112221111... instead. which makes sense also.
There's a couple steps involved. I don't have any videos. 1) example request: @GET("your_url") suspend fun getStuff(): Call 2) getting the result: GlobalScope.launch { val result = apiSerivce.getStuff().execute() }
delay() is a non-blocking function, so these jobs are not actually parallel. You can replace delay() with Thread.sleep() to see that it will take 2.7 seconds to complete both jobs
I just don't understand how can you explain such a confusing topic with so much ease. You are an amazing awesome and relatable teacher, mitch
Thanks for the video! I was watching another video of yours about memory leaking, and I think would be interesting to join these concepts into one video: like an example of memory leaking with coroutines.. Best practices to avoid it, etc..
I love it. Coroutine is quite confusing at first. U are making it simpler easy to understand. Thanks gbu
I still got confused...=/
@@felipepereira3061 ua-cam.com/video/C38lG2wraoo/v-deo.html watch this series full
I have a technical job interview today, this is the best way to start the day with a refresh of coroutines :D
Always checking Codingwithmitch ™ for all your android job prep needs ;)
Great work mitch.. Very nice and informative video.. :)
Great tutorials, very helpful and descriptive. Loved the part where u corrected ur self with “technically they won’t run at the same time” . Your attention to details is really commendable. Good stuff mate 👌
Great content Mitch! Keep it up!
Thanks for this amazing tutorial, hope for more
Just What I needed!!
I'm a mind reader
Thanks for awesome videos of coroutines. They really helped me clearing up my concepts on this topic.
Do you work in a hospital now?
Yes. Where do you record?
@@codingwithmitch Because of your shirt. Looks like someone from "Scrubs"
nice meet :D )))
Hi Mitch , If we are using CoroutineScope(IO).launch{ } as parent scope for our child scope then if one fails then other won't be working right? In such case how can we execute Parellel?
Simply Great
Async/await allows creating all of the `jobs` immediately without executing them, you can do that when necessary if at all.
When to use async await and when to use Launch->
Async Await -> If you want to wait to update UI after finishing all coroutines, (even all coroutines are executing parallel) go for async-await.
Launch-> All parallel executions are updating UI after finishing their execution.
This is my understanding of both of these functionalities.
@codingWithMitch
Continue to read our minds.
I love you Mitch
Thanx man this was very helpful 😊
I appreciate a lot thanks.Great work !!!
I found less videos on handling exception while making api calls using coroutine.
I found sometime please update us on exception handling.
Nice brother . Good job .I like more your video tutorials.
thank you so much...amazing video
Thanks Mitch ✨🙂🙌
Another fantastic video
Awesome man! keep it going!
Thanks Mitch 😊👍
Sir, I'm watching your good videos for already a long time now and I only wanted to say that I think maybe it would be better for people learning this if you could be a litle bit slower. Since you understand all the topics so well you are so fast and sometimes it gets difficult to follow. Thanks!
If you switched the order on those awaits, both would wait until job2 finished before setting text, right? Since the first set text would await job2 before moving on to the second await?
Awesome video.. keep on
❤️❤️
Loved it😁
Returning values from asynchronous callback listeners? So i have an example (in Java from API documentation, but i work in Kotlin personally)
What's a good way to return values from the onSuccess or onError callback methods here? Currently i am using MutableLiveData and LiveData and then observing a DataState like value and doing something on that. BUT is there a better way or cleaner way to handle returning a value from onSuccess/onError? Oh yeah i went to create this method in a service or repository and call it from a ViewModel.
sessionClient.authorizedRequest(uri, properties, postParameters, HttpConnection.RequestMethod.POST,
new RequestCallback() {
@Override
public void onSuccess(@NonNull JSONObject result) {
//handle JSONObject result.
}
@Override
public void onError(String error, AuthorizationException exception) {
//handle error
}
});
Just got confused, Using the launch if the 2 jobs are running parallel then the overall time taken should be Job2's time right ? since it running in parallel Job 1 should have completed before Job2. Please correct me if my understanding is wrong.
I am getting Unresolved reference: await , what can I do so for. does it required any special coroutine dependency?
Hi @CodingWithMitch , I have a doubt. , Why Job1 and Job2 are running on different thread . When they are fired in same scope of coroutine . As you said Coroutine are not threads they are like job which perform on same thread .
Thank you 👍
Hi Mitch, is it possible to create a timer app using Kotlin with very high accuracy? i tried but its not accurate when i put delay of 1000 ms and very inaccurate when i put delay of 100 ms
Great electrifying
I think the two jobs are in same IO scope and will run on same thread that is why the name of the thread is same.But i'm confused why async was having different thread names , I have tried it on my device they ran on same thread.
Nice, thank you)
what is the difference between withcontext{} and CoroutineScope{} ?
how to return Response to fakeAPIRequest() function which comes in corotuine
Thank You
Thanks bro
When next sell in coming waiting for good discount?
please make video about coroutine flow
Watch any of the courses on my website
Engaging da twisty motirs
Is there a max amount of jobs/asyncs you can do? Is this automatically handled?
There is no hard limit. But I'm sure it's possible to reach a limit. It would depend on how heavy the work you were doing was. The limitation would be on the device hardware not the software
super!
So the second result2.await() won't execute until result1.await() gets a result?
Yes. Await will wait till it has the result.
Run two loops, one that prints "1" other one that prints "2". If log is 1111122222 than they don't run in parallel and if log is 1212121212 (for example, the thing is that 1 and 2 intertwine) than they are working in parallel.
my experience is it's more like this: 1122212211122...
@@gabormiklay9209 Great. The point is if the intertwine than they work in parallel.
Yep
@@markonovakovic3838 yeah, sure, i was just expecting the same 121212... pattern when i first ran paralell coroutines. and i got 111222111111222221112221111... instead. which makes sense also.
@@gabormiklay9209 😄. Great. Am glad you ran the example
sheeeeeeeeeeesh
The key take away from this video is that it's better to use async when your suspend functions and coroutines blocks have a return type.
How can i use this with actual api?
By watching my courses of course: codingwithmitch.com/courses/powerful-android-apps-with-jetpack-architecture/
Bruh,but do you even perpendicular tasks?
obviously
How to use Coroutines & Retofit together?
There's a couple steps involved. I don't have any videos.
1) example request:
@GET("your_url")
suspend fun getStuff(): Call
2) getting the result:
GlobalScope.launch {
val result = apiSerivce.getStuff().execute()
}
@@codingwithmitch
@GET("placeholder/user/{userId}")
suspend fun getUSer(
@Path("userId")
userId: String
): User
2-
fun getUSer(userID: String): LiveData {
job = Job()
return object : LiveData() {
override fun onActive() {
super.onActive()
job?.let { thejob ->
CoroutineScope(Dispatchers.IO + thejob).launch {
val user = RetrofitBuider.apiService.getUSer(userID)
withContext(Main) {
value = user
thejob.complete()
}
}
}
}
}
}
engagement
delay() is a non-blocking function, so these jobs are not actually parallel. You can replace delay() with Thread.sleep() to see that it will take 2.7 seconds to complete both jobs
Is the UI frozen until jobs are done ?
delay is already deprecated, if you use it the app will be worthless next year...
daddy.. l love you
😘😘
N gaged