PARALLEL Background Tasks with Kotlin Coroutines (ASYNC AND AWAIT)

Поділитися
Вставка
  • Опубліковано 3 гру 2024

КОМЕНТАРІ • 87

  • @anshsachdeva850
    @anshsachdeva850 3 роки тому +10

    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

  • @victormagosso2572
    @victormagosso2572 3 роки тому +2

    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..

  • @sagarghare9829
    @sagarghare9829 4 роки тому +3

    I love it. Coroutine is quite confusing at first. U are making it simpler easy to understand. Thanks gbu

    • @felipepereira3061
      @felipepereira3061 4 роки тому

      I still got confused...=/

    • @sagarghare9829
      @sagarghare9829 4 роки тому

      @@felipepereira3061 ua-cam.com/video/C38lG2wraoo/v-deo.html watch this series full

  • @n-o-i-d
    @n-o-i-d 5 років тому +7

    I have a technical job interview today, this is the best way to start the day with a refresh of coroutines :D

    • @codingwithmitch
      @codingwithmitch  5 років тому +6

      Always checking Codingwithmitch ™ for all your android job prep needs ;)

  • @ajaykumarvishwakarma4720
    @ajaykumarvishwakarma4720 3 роки тому +1

    Great work mitch.. Very nice and informative video.. :)

  • @triarcdeveloper8777
    @triarcdeveloper8777 4 роки тому

    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 👌

  • @MAAMM96
    @MAAMM96 4 роки тому +1

    Great content Mitch! Keep it up!

  • @srjlove2102
    @srjlove2102 5 років тому +2

    Thanks for this amazing tutorial, hope for more

  • @ignatiusn9851
    @ignatiusn9851 5 років тому +3

    Just What I needed!!

  • @flintskeen1828
    @flintskeen1828 4 роки тому

    Thanks for awesome videos of coroutines. They really helped me clearing up my concepts on this topic.

  • @codinginflow
    @codinginflow 5 років тому +24

    Do you work in a hospital now?

  • @MyDanish100
    @MyDanish100 Рік тому +1

    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?

  • @adityagupta375
    @adityagupta375 2 роки тому +1

    Simply Great

  • @theANSWERisXLII
    @theANSWERisXLII 5 років тому

    Async/await allows creating all of the `jobs` immediately without executing them, you can do that when necessary if at all.

  • @snehalshinde7838
    @snehalshinde7838 Рік тому

    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

  • @buzzminkyunghoon3856
    @buzzminkyunghoon3856 5 років тому +2

    Continue to read our minds.

  • @MMB3245
    @MMB3245 2 роки тому +1

    I love you Mitch

  • @techmarinar
    @techmarinar 3 роки тому

    Thanx man this was very helpful 😊

  • @srivatsadivya1114
    @srivatsadivya1114 4 роки тому

    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.

  • @mathavank
    @mathavank 4 роки тому

    Nice brother . Good job .I like more your video tutorials.

  • @bhagavanreddy8075
    @bhagavanreddy8075 5 років тому +1

    thank you so much...amazing video

  • @Punarjagran
    @Punarjagran 3 роки тому

    Thanks Mitch ✨🙂🙌

  • @danielwatts3718
    @danielwatts3718 4 роки тому

    Another fantastic video

  • @octaviancservid9945
    @octaviancservid9945 3 роки тому

    Awesome man! keep it going!

  • @sathishkumarsingaraveni3049
    @sathishkumarsingaraveni3049 5 років тому +1

    Thanks Mitch 😊👍

  • @Daaaaaaavid
    @Daaaaaaavid 5 років тому

    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!

  • @commentsonthetube14
    @commentsonthetube14 3 роки тому

    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?

  • @nerminahmed6927
    @nerminahmed6927 4 роки тому

    Awesome video.. keep on

  • @o.z.sidd.
    @o.z.sidd. Рік тому +1

    ❤️❤️

  • @bhuvneshvarma7843
    @bhuvneshvarma7843 3 роки тому

    Loved it😁

  • @bryanneuberger5886
    @bryanneuberger5886 3 роки тому

    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
    }
    });

  • @karthikgaddam1146
    @karthikgaddam1146 2 роки тому

    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.

  • @asadansar6214
    @asadansar6214 3 роки тому

    I am getting Unresolved reference: await , what can I do so for. does it required any special coroutine dependency?

  • @vivek-ts8fg
    @vivek-ts8fg 4 роки тому

    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 .

  • @punitgupta7175
    @punitgupta7175 3 роки тому

    Thank you 👍

  • @yogeshmishra6025
    @yogeshmishra6025 3 роки тому

    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

  • @vanchikt
    @vanchikt 2 роки тому

    Great electrifying

  • @slvinaykumar
    @slvinaykumar 4 роки тому

    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.

  • @ИванЕмелин-ш9ш
    @ИванЕмелин-ш9ш 3 роки тому

    Nice, thank you)

  • @abdelrahmanesam3684
    @abdelrahmanesam3684 4 роки тому

    what is the difference between withcontext{} and CoroutineScope{} ?

  • @kondalraotirumalasetty3908
    @kondalraotirumalasetty3908 2 роки тому

    how to return Response to fakeAPIRequest() function which comes in corotuine

  • @devdeeds
    @devdeeds 3 роки тому

    Thank You

  • @vigneshwaran-gd8yy
    @vigneshwaran-gd8yy 2 роки тому

    Thanks bro

  • @hareshlakhwani4721
    @hareshlakhwani4721 5 років тому

    When next sell in coming waiting for good discount?

  • @TuanBuianonymous
    @TuanBuianonymous 2 роки тому

    please make video about coroutine flow

  • @ChrisAthanas
    @ChrisAthanas 4 роки тому +1

    Engaging da twisty motirs

  • @deniteappz9250
    @deniteappz9250 4 роки тому

    Is there a max amount of jobs/asyncs you can do? Is this automatically handled?

    • @codingwithmitch
      @codingwithmitch  4 роки тому +1

      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

  • @serggio88888
    @serggio88888 4 роки тому

    super!

  • @rashedulhasan5372
    @rashedulhasan5372 5 років тому

    So the second result2.await() won't execute until result1.await() gets a result?

    • @24035709
      @24035709 4 роки тому

      Yes. Await will wait till it has the result.

  • @markonovakovic3838
    @markonovakovic3838 5 років тому

    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.

    • @gabormiklay9209
      @gabormiklay9209 5 років тому

      my experience is it's more like this: 1122212211122...

    • @markonovakovic3838
      @markonovakovic3838 5 років тому

      @@gabormiklay9209 Great. The point is if the intertwine than they work in parallel.

    • @ShivamJha00
      @ShivamJha00 5 років тому

      Yep

    • @gabormiklay9209
      @gabormiklay9209 5 років тому +1

      @@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.

    • @markonovakovic3838
      @markonovakovic3838 5 років тому

      @@gabormiklay9209 😄. Great. Am glad you ran the example

  • @siddharthsingh420
    @siddharthsingh420 2 роки тому

    sheeeeeeeeeeesh

  • @Alchemist10241
    @Alchemist10241 3 роки тому

    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.

  • @mohameddarwish1347
    @mohameddarwish1347 4 роки тому

    How can i use this with actual api?

    • @codingwithmitch
      @codingwithmitch  4 роки тому +1

      By watching my courses of course: codingwithmitch.com/courses/powerful-android-apps-with-jetpack-architecture/

  • @micosair
    @micosair 5 років тому +1

    Bruh,but do you even perpendicular tasks?

  • @amitsaha3493
    @amitsaha3493 5 років тому

    How to use Coroutines & Retofit together?

    • @codingwithmitch
      @codingwithmitch  5 років тому +2

      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()
      }

    • @ahmedtawfiq4723
      @ahmedtawfiq4723 4 роки тому

      @@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()
      }
      }
      }
      }
      }
      }

  • @bryanneuberger5886
    @bryanneuberger5886 3 роки тому

    engagement

  • @t3ddyss
    @t3ddyss 3 роки тому

    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

  • @williampoulin121
    @williampoulin121 4 роки тому

    Is the UI frozen until jobs are done ?

  • @dasstraat
    @dasstraat 3 роки тому

    delay is already deprecated, if you use it the app will be worthless next year...

  • @oscarperry641
    @oscarperry641 4 роки тому +1

    daddy.. l love you

  • @harshar6897
    @harshar6897 3 роки тому

    N gaged