Android Makers -- Concurrency doesn’t have to be hard: Kotlin Coroutines & Channels
Presentation of the fundamentals of Kotlin Coroutines, Channels and Flows presented at Android Makers'19
*NOTE* Several animations are not present in this slide deck; the presentation switched between live coding and slides
private val portafilterTwo: SendChannel<CoffeeBean.GroundBeans> = actor {...} suspend fun pullEspressoShot(groundBeans: CoffeeBean.GroundBeans): Espresso { return select { portafilterOne.onSend(groundBeans) { TODO("sent to portafilter one - wait for result") } portafilterTwo.onSend(groundBeans) { TODO("sent to portafilter two - wait for result") } } } ... } https://jagstalk.page.link/examples
private val portafilterTwo: SendChannel<CoffeeBean.GroundBeans> = actor {...} suspend fun pullEspressoShot(groundBeans: CoffeeBean.GroundBeans): Espresso { return select { portafilterOne.onSend(groundBeans) { TODO("sent to portafilter one - wait for result") } portafilterTwo.onSend(groundBeans) { TODO("sent to portafilter two - wait for result") } } } ... } https://jagstalk.page.link/examples
val groundBeans: CoffeeBean.GroundBeans ) private val portafilterOne: SendChannel<CoffeeBean.GroundBeans> = actor {...} private val portafilterTwo: SendChannel<CoffeeBean.GroundBeans> = actor {...} suspend fun pullEspressoShot(groundBeans: CoffeeBean.GroundBeans): Espresso { return select { portafilterOne.onSend(groundBeans) { TODO("sent to portafilter one - wait for result") } portafilterTwo.onSend(groundBeans) { TODO("sent to portafilter two - wait for result") } } } ... } https://jagstalk.page.link/examples
val groundBeans: CoffeeBean.GroundBeans ) private val portafilterOne: SendChannel<EspressoShotRequest> = actor { consumeEach { request -> val espresso = processEspressoShot(request.groundBeans) request.deferredEspressoShot.complete(espresso) } } private val portafilterTwo: SendChannel<EspressoShotRequest> = actor {...} suspend fun pullEspressoShot(groundBeans: CoffeeBean.GroundBeans): Espresso { return select { portafilterOne.onSend(groundBeans) { TODO("sent to portafilter one - wait for result") } portafilterTwo.onSend(request) { TODO("sent to portafilter two - wait for result") } } } ... } https://jagstalk.page.link/examples