Merge branch 'master' into develop
diff --git a/common/kotlinx-coroutines-core-common/src/CoroutineScope.kt b/common/kotlinx-coroutines-core-common/src/CoroutineScope.kt
index 3256015..178163c 100644
--- a/common/kotlinx-coroutines-core-common/src/CoroutineScope.kt
+++ b/common/kotlinx-coroutines-core-common/src/CoroutineScope.kt
@@ -163,7 +163,7 @@
* ... load some UI data ...
* }
*
- * withContext(UI) {
+ * withContext(Dispatchers.Main) {
* doSomeWork()
* val result = data.await()
* display(result)
diff --git a/common/kotlinx-coroutines-core-common/src/channels/Channel.kt b/common/kotlinx-coroutines-core-common/src/channels/Channel.kt
index 5a88141..389cece 100644
--- a/common/kotlinx-coroutines-core-common/src/channels/Channel.kt
+++ b/common/kotlinx-coroutines-core-common/src/channels/Channel.kt
@@ -111,7 +111,7 @@
* events.offer(event)
* }
*
- * val uiUpdater = launch(UI, parent = UILifecycle) {
+ * val uiUpdater = launch(Dispatchers.Main, parent = UILifecycle) {
* events.consume {}
* events.cancel()
* }
diff --git a/core/kotlinx-coroutines-core/src/ThreadContextElement.kt b/core/kotlinx-coroutines-core/src/ThreadContextElement.kt
index 959bc38..68098f3 100644
--- a/core/kotlinx-coroutines-core/src/ThreadContextElement.kt
+++ b/core/kotlinx-coroutines-core/src/ThreadContextElement.kt
@@ -40,7 +40,7 @@
* }
*
* // Usage
- * launch(UI + CoroutineName("Progress bar coroutine")) { ... }
+ * launch(Dispatchers.Main + CoroutineName("Progress bar coroutine")) { ... }
* ```
*
* Every time this coroutine is resumed on a thread, UI thread name is updated to
@@ -90,7 +90,7 @@
* println(myThreadLocal.get()) // Prints "null"
* launch(Dispatchers.Default + myThreadLocal.asContextElement(value = "foo")) {
* println(myThreadLocal.get()) // Prints "foo"
- * withContext(UI) {
+ * withContext(Dispatchers.Main) {
* println(myThreadLocal.get()) // Prints "foo", but it's on UI thread
* }
* }
@@ -101,7 +101,7 @@
*
* ```
* myThreadLocal.set("main")
- * withContext(UI) {
+ * withContext(Dispatchers.Main) {
* println(myThreadLocal.get()) // Prints "main"
* myThreadLocal.set("UI")
* }
diff --git a/native/kotlinx-coroutines-core-native/src/CoroutineContext.kt b/native/kotlinx-coroutines-core-native/src/CoroutineContext.kt
index d846569..6aef310 100644
--- a/native/kotlinx-coroutines-core-native/src/CoroutineContext.kt
+++ b/native/kotlinx-coroutines-core-native/src/CoroutineContext.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.internal.*
private fun takeEventLoop(): EventLoopImpl =
- ThreadLocalEventLoop.currentOrNull() as EventLoopImpl ?:
+ ThreadLocalEventLoop.currentOrNull() as? EventLoopImpl ?:
error("There is no event loop. Use runBlocking { ... } to start one.")
internal object DefaultExecutor : CoroutineDispatcher(), Delay {
diff --git a/native/kotlinx-coroutines-core-native/src/CoroutineExceptionHandlerImpl.kt b/native/kotlinx-coroutines-core-native/src/CoroutineExceptionHandlerImpl.kt
index 2219339..5efa924 100644
--- a/native/kotlinx-coroutines-core-native/src/CoroutineExceptionHandlerImpl.kt
+++ b/native/kotlinx-coroutines-core-native/src/CoroutineExceptionHandlerImpl.kt
@@ -8,5 +8,5 @@
internal actual fun handleCoroutineExceptionImpl(context: CoroutineContext, exception: Throwable) {
// log exception
- println(exception)
+ exception.printStackTrace()
}
diff --git a/native/kotlinx-coroutines-core-native/test/DelayExceptionTest.kt b/native/kotlinx-coroutines-core-native/test/DelayExceptionTest.kt
new file mode 100644
index 0000000..463712c
--- /dev/null
+++ b/native/kotlinx-coroutines-core-native/test/DelayExceptionTest.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package kotlinx.coroutines
+
+import kotlin.coroutines.*
+import kotlin.test.Test
+import kotlin.test.assertTrue
+
+class DelayExceptionTest {
+ private object Dispatcher : CoroutineDispatcher() {
+ override fun isDispatchNeeded(context: CoroutineContext): Boolean = true
+ override fun dispatch(context: CoroutineContext, block: Runnable) { block.run() }
+ }
+
+ private lateinit var exception: Throwable
+
+
+ @Test
+ fun testThrowsTce() {
+ CoroutineScope(Dispatcher + CoroutineExceptionHandler { _, e -> exception = e }).launch {
+ delay(10)
+ }
+
+ assertTrue(exception is IllegalStateException)
+ }
+}