Skip to content

Commit a88f628

Browse files
committed
Update documentation in favor of Dispatchers.Main
Fixes #803 Fixes #802
1 parent 32178b8 commit a88f628

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

common/kotlinx-coroutines-core-common/src/CoroutineScope.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import kotlin.coroutines.intrinsics.*
4545
* * Note how coroutine builders are scoped: if activity is destroyed or any of the launched coroutines
4646
* * in this method throws an exception, then all nested coroutines are cancelled.
4747
* */
48-
* fun loadDataFromUI() = launch { // <- extension on current activity, launched in the main thread
48+
* fun showSomeData() = launch { // <- extension on current activity, launched in the main thread
4949
* val ioData = async(Dispatchers.IO) { // <- extension on launch scope, launched in IO dispatcher
5050
* // blocking I/O operation
5151
* }
@@ -177,13 +177,13 @@ object GlobalScope : CoroutineScope {
177177
* Example of the scope usages looks like this:
178178
*
179179
* ```
180-
* suspend fun loadDataForUI() = coroutineScope {
180+
* suspend fun showSomeData() = coroutineScope {
181181
*
182182
* val data = async { // <- extension on current scope
183183
* ... load some UI data ...
184184
* }
185185
*
186-
* withContext(UI) {
186+
* withContext(Dispatchers.Main) {
187187
* doSomeWork()
188188
* val result = data.await()
189189
* display(result)
@@ -192,9 +192,9 @@ object GlobalScope : CoroutineScope {
192192
* ```
193193
*
194194
* Semantics of the scope in this example:
195-
* 1) `loadDataForUI` returns as soon as data is loaded and UI is updated.
196-
* 2) If `doSomeWork` throws an exception, then `async` task is cancelled and `loadDataForUI` rethrows that exception.
197-
* 3) If outer scope of `loadDataForUI` is cancelled, both started `async` and `withContext` are cancelled.
195+
* 1) `showSomeData` returns as soon as data is loaded and displayed in UI.
196+
* 2) If `doSomeWork` throws an exception, then `async` task is cancelled and `showSomeData` rethrows that exception.
197+
* 3) If outer scope of `showSomeData` is cancelled, both started `async` and `withContext` are cancelled.
198198
*
199199
* Method may throw [CancellationException] if the current job was cancelled externally
200200
* or may throw the corresponding unhandled [Throwable] if there is any unhandled exception in this scope
@@ -226,7 +226,6 @@ public fun CoroutineScope(context: CoroutineContext): CoroutineScope =
226226
* Example of use:
227227
* ```
228228
* class MyAndroidActivity: CoroutineScope by MainScope(CoroutineName("MyActivity"))) {
229-
*
230229
* override fun onDestroy() {
231230
* super.onDestroy()
232231
* cancel() // CoroutineScope.cancel

core/kotlinx-coroutines-core/src/ThreadContextElement.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ import kotlin.coroutines.*
4040
* }
4141
*
4242
* // Usage
43-
* launch(UI + CoroutineName("Progress bar coroutine")) { ... }
43+
* launch(Dispatchers.Main + CoroutineName("Progress bar coroutine")) { ... }
4444
* ```
4545
*
46-
* Every time this coroutine is resumed on a thread, UI thread name is updated to
47-
* "UI thread original name # Progress bar coroutine" and the thread name is restored to the original one when
46+
* Every time this coroutine is resumed on a thread, Main thread name is updated to
47+
* "Main thread original name # Progress bar coroutine" and the thread name is restored to the original one when
4848
* this coroutine suspends.
4949
*
5050
* To use [ThreadLocal] variable within the coroutine use [ThreadLocal.asContextElement][asContextElement] function.

0 commit comments

Comments
 (0)