Skip to content

Commit 54d57e0

Browse files
ScottPierceelizarov
authored andcommitted
Check for undefined window.addEventListener when choosing default coroutine dispatcher.
Fixes #230
1 parent 8d51c9c commit 54d57e0

File tree

1 file changed

+2
-2
lines changed
  • js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental

1 file changed

+2
-2
lines changed

js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineContext.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public actual object Unconfined : CoroutineDispatcher() {
4040
* This is the default [CoroutineDispatcher] that is used by all standard builders like
4141
* [launch], [async], etc if no dispatcher nor any other [ContinuationInterceptor] is specified in their context.
4242
*/
43-
@Suppress("PropertyName")
43+
@Suppress("PropertyName", "UnsafeCastFromDynamic")
4444
public actual val DefaultDispatcher: CoroutineDispatcher = when {
4545
// Check if we are in the browser and must use window.postMessage to avoid setTimeout throttling
46-
jsTypeOf(window) != "undefined" -> window.asCoroutineDispatcher()
46+
jsTypeOf(window) != "undefined" && jsTypeOf(window.asDynamic().addEventListener) != "undefined" -> window.asCoroutineDispatcher()
4747
else -> NodeDispatcher()
4848
}
4949

0 commit comments

Comments
 (0)