Skip to content

Instantly share code, notes, and snippets.

@selmanon
Last active April 17, 2019 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selmanon/7f26205e34458c9a1cc233a67eb6a7b1 to your computer and use it in GitHub Desktop.
Save selmanon/7f26205e34458c9a1cc233a67eb6a7b1 to your computer and use it in GitHub Desktop.
Kotlin Coroutines
API (class) Key words : Job, Scope, Context, Dispatchers
- Suspending functions do not block the caller thread.
- Job (is a Element is a Context)
- A background job
- Can be cancled else a CancellationException is rised
- Had a lifecycle
- A Job had childs and can be a parent
- Cancelling a parent Job leads to cancel it's childs
- If child job fail the whole jobs (parent and childs) are canelled
- An instance of a Job could be get by a launch coroutine builder or by a Job() factory function
- A Job doesn't return a result else there's the Deffered version of Job that do return a result
-Scope (has a context)
- GlobalScope.launch create a top-level coroutine // like creating a main thread
- Coroutine has a Context and Job has a Context
- `coroutineScope` function
- Allow parallel decomposition of work (block)
- If a coroutine children scope fail the other blocks got canceled.
- Context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment