Last active
April 17, 2019 12:37
-
-
Save selmanon/7f26205e34458c9a1cc233a67eb6a7b1 to your computer and use it in GitHub Desktop.
Kotlin Coroutines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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