Skip to content

Instantly share code, notes, and snippets.

@jiffle
Last active June 20, 2018 05:16
Show Gist options
  • Save jiffle/6287023c79e290dc96dc19bfff520b70 to your computer and use it in GitHub Desktop.
Save jiffle/6287023c79e290dc96dc19bfff520b70 to your computer and use it in GitHub Desktop.
Guide on Kotlin Coroutines for muggles

Core Language Methods

Block method Returns Thread Notes
launch Job From Pool parameter
async Deferred From Pool parameter Use await to get result
withTimeout value from Coroutine From Pool parameter
thread Null New thread Not a coroutine, but same as launch

Launch Methods

cancel cancels the coroutine job execution cancelAndJoin cancels the job and waits for its completion

Async Arguments

start = CoroutineStart.LAZY) starts an async routine only when it's needed

Coroutine Contexts

Unconfined - Main thread coroutineContext - Main thread CommonPool - ForkJoinPool <specificThread> -

Closure Properties

isActive set to false if computation is cancelled

Kotlinx Methods

Block method Returns Thread Closure Method Notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment