Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | package kotlinx.coroutines.experimental |
| 6 | |
| 7 | import kotlinx.coroutines.experimental.internal.* |
| 8 | |
Roman Elizarov | dbd9e1c | 2018-04-28 15:14:18 +0300 | [diff] [blame] | 9 | internal actual abstract class CompletionHandlerBase : LinkedListNode() { |
| 10 | @JsName("invoke") |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 11 | actual abstract fun invoke(cause: Throwable?) |
| 12 | } |
| 13 | |
Roman Elizarov | dbd9e1c | 2018-04-28 15:14:18 +0300 | [diff] [blame] | 14 | @Suppress("UnsafeCastFromDynamic") |
| 15 | internal actual inline val CompletionHandlerBase.asHandler: CompletionHandler get() = asDynamic() |
| 16 | |
| 17 | internal actual abstract class CancelHandlerBase { |
| 18 | @JsName("invoke") |
Vsevolod Tolstopyatov | f3a5013 | 2018-04-16 19:41:20 +0300 | [diff] [blame] | 19 | actual abstract fun invoke(cause: Throwable?) |
| 20 | } |
| 21 | |
Roman Elizarov | dbd9e1c | 2018-04-28 15:14:18 +0300 | [diff] [blame] | 22 | @Suppress("UnsafeCastFromDynamic") |
| 23 | internal actual inline val CancelHandlerBase.asHandler: CompletionHandler get() = asDynamic() |
| 24 | |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 25 | internal actual fun CompletionHandler.invokeIt(cause: Throwable?) { |
| 26 | when(jsTypeOf(this)) { |
| 27 | "function" -> invoke(cause) |
Roman Elizarov | dbd9e1c | 2018-04-28 15:14:18 +0300 | [diff] [blame] | 28 | else -> asDynamic().invoke(cause) |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 29 | } |
| 30 | } |