Coroutine Scopes - Kotlin Coroutines

Поділитися
Вставка
  • Опубліковано 22 лип 2024
  • 🏆 My Online Courses
    ⭐Discount Coupon: LAUNCH-STEVDZA-SAN
    stevdza-san.com
    🐱‍👤 Wanna become a member? Join!
    / @stevdzasan
    📸 Instagram
    / stevdza_san
    Kotlin coroutines provide an API that enables you to write asynchronous code. With Kotlin coroutines, you can define a CoroutineScope, which helps you to manage when your coroutines should run. Each asynchronous operation runs within a particular scope.
    Global scope is used to launch top-level coroutines which are operating on the whole application lifetime and are not cancelled prematurely.
    A LifecycleScope is defined for each Lifecycle object. Any coroutine launched in this scope is canceled when the Lifecycle is destroyed.
    A ViewModelScope is defined for each ViewModel in your app. Any coroutine launched in this scope is automatically canceled if the ViewModel is cleared. Coroutines are useful here for when you have work that needs to be done only if the ViewModel is active. For example, if you are computing some data for a layout, you should scope the work to the ViewModel so that if the ViewModel is cleared, the work is canceled automatically to avoid consuming resources.
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    Other videos:
    The Basics - • The Basics - Kotlin Co...
    Jobs & Cancellation - • Jobs and Cancellation ...
    runBlocking - • runBlocking - Kotlin C...
    withContext - • withContext() - Kotlin...
    🕒Timestamps:
    0:00 - Introduction
    3:00 - Create Coroutine Scope
    7:50 - GlobalScope
    10:47 - lifecycleScope & viewModelScope

КОМЕНТАРІ • 34

  • @duncanmoiyo6069
    @duncanmoiyo6069 8 місяців тому +2

    You've significantly simplified the comprehension of coroutine scopes. I truly appreciate it.

  • @kristofs8893
    @kristofs8893 2 роки тому +10

    I had no chance of understanding Coroutines, but you made it look so simple!

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

      Yay, happy to hear that buddy!

  • @Axelfromthehudjelud
    @Axelfromthehudjelud 2 роки тому +2

    Ok, this is the best explanation of the things that were confusing me. Thank you very much!

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

    Thank you for all the good content!

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

    Very well explained and demonstrated, thank you. 🙌

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

    Loved your explanation style !! Keep up the good work !!

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

    It amazes me how quickly and easily this topic can be explained and shown !!!

  • @100rabhGrwal
    @100rabhGrwal 3 роки тому +7

    Thankyou dear for this easy and understandable explanation 👍

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

    That is my man never disappoint, You are the best

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

    It is amazing! I finally understand what happen when we use lifecyclescope

  • @vaibhavarora8793
    @vaibhavarora8793 2 місяці тому

    Thank You , It was very useful.

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

    You are amazing. Thanks for the content.

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

    Yes please do more videos like this!

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

    best explanation ever, thanks too much

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

    Thanks!

  • @slobom.6744
    @slobom.6744 Рік тому

    Great Explanation, thanks bro

  • @michaelappiah-kubi2829
    @michaelappiah-kubi2829 8 місяців тому

    Thank you

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

    The best!

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

    Thank you ...

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

    Very nice

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

    So there is no way to use a LifecycleScope or ViewModelScope inside of an Adapter class?

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

    What is difference between CoroutineScope and GLobalScope about their lifcecycles? when CoroutineScope Cancells autmatically?

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

    Make a detailed video on Coroutine Jobs

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

    what if you created an infinite loop without using "delay" and instead system time difference, I think it will not be cancelled even if the coroutine is tied to the lifecycle.

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

    хорошие видео для понимания

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

    +1 thank you :)

  • @ajayvamsee7508
    @ajayvamsee7508 6 місяців тому

    So you mention global scope coroutine will run even fragment A is destroyed but after again come back to fragment A the fragment A will start again right then coroutine will start again..
    So we have 2 coroutines or what will happens..?

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

    Will there be a jetpack compose course?

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

      Definitely in the future

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

    I like this... but want to know is there any better content for proffessionals?

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

    When u create video use android studio default theme, it will be very clear for visibility as compare to dracula theme