blob: fcd028a2682b15eb919feb3dddb680f8ebdcbc5a [file] [log] [blame]
Roman Elizarovaa461cf2018-04-11 13:20:29 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarovaa461cf2018-04-11 13:20:29 +03003 */
4
5package kotlinx.coroutines.experimental
6
7import kotlinx.coroutines.experimental.internal.*
8
Roman Elizarovdbd9e1c2018-04-28 15:14:18 +03009internal actual abstract class CompletionHandlerBase : LinkedListNode() {
10 @JsName("invoke")
Roman Elizarovaa461cf2018-04-11 13:20:29 +030011 actual abstract fun invoke(cause: Throwable?)
12}
13
Roman Elizarovdbd9e1c2018-04-28 15:14:18 +030014@Suppress("UnsafeCastFromDynamic")
15internal actual inline val CompletionHandlerBase.asHandler: CompletionHandler get() = asDynamic()
16
17internal actual abstract class CancelHandlerBase {
18 @JsName("invoke")
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +030019 actual abstract fun invoke(cause: Throwable?)
20}
21
Roman Elizarovdbd9e1c2018-04-28 15:14:18 +030022@Suppress("UnsafeCastFromDynamic")
23internal actual inline val CancelHandlerBase.asHandler: CompletionHandler get() = asDynamic()
24
Roman Elizarovaa461cf2018-04-11 13:20:29 +030025internal actual fun CompletionHandler.invokeIt(cause: Throwable?) {
26 when(jsTypeOf(this)) {
27 "function" -> invoke(cause)
Roman Elizarovdbd9e1c2018-04-28 15:14:18 +030028 else -> asDynamic().invoke(cause)
Roman Elizarovaa461cf2018-04-11 13:20:29 +030029 }
30}