Code Monkey home page Code Monkey logo

coroutine-playground's Introduction

Android Coroutine Playground

Explore Kotlin Coroutine Possibility

Explore List

  • Basic suspend function
  • Scopes
  • Coroutine Unit Test
  • Flow & Channel
  • Async
  • Integrate with RxJava
  • Feature Comparison with RxJava
    • Completable
    • Zip
    • Merge
    • Debounce & Delay

Result

Basic suspend function

suspend (sus·pend, /səˈspend/) - temporarity prevent from continuing or being in force or effect

  • can invoke by another suspend function or within coroutine
  • it like pause and resume (not blocking thread)
  • sequential function
  • complie to function with callback interface Continuation<T>
public interface Continuation<in T> {
    /**
     * The context of the coroutine that corresponds to this continuation.
     */
    public val context: CoroutineContext

    /**
     * Resumes the execution of the corresponding coroutine passing a successful or failed [result] as the
     * return value of the last suspension point.
     */
    public fun resumeWith(result: Result<T>)
}
Coroutine unit Test

In my opinoin testing coroutine can saparate into 2 category

  • Testing ViewModel
    • You have to stub TestCoroutineDispatcher into Dispatchers.setMain(dispatcher: CoroutineDispatcher) at call resetMain() after done testing
  • Testing basic suspend function
    • For basic suspend function can be done the same way, if you run it on main thread.
    • For IO or other thread except main you should create coroutine context provider and stub it when testing
    interface CoroutineContextProvider {
    
        val Main: CoroutineContext
    
        val IO: CoroutineContext
    
    }

coroutine-playground's People

Contributors

watsaponk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.