1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-03-26 07:20:09 +08:00

Add common runBlocking for convenience

This commit is contained in:
Him188 2020-04-08 10:49:04 +08:00
parent a69d6e2ecd
commit d9756c212c
3 changed files with 46 additions and 0 deletions
mirai-core/src
androidMain/kotlin/net/mamoe/mirai/utils/internal
commonMain/kotlin/net.mamoe.mirai/utils/internal
jvmMain/kotlin/net/mamoe/mirai/utils/internal

View File

@ -0,0 +1,12 @@
package net.mamoe.mirai.utils.internal
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext
/**
* Mirror of `runBlocking` from `kotlinx.serialization` on JVM
*/
internal actual fun <T> runBlocking(
context: CoroutineContext,
block: suspend CoroutineScope.() -> T
): T = kotlinx.coroutines.runBlocking(context, block)

View File

@ -0,0 +1,22 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.utils.internal
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
/**
* Mirror of `runBlocking` from `kotlinx.serialization` on JVM.
*/
internal expect fun <T> runBlocking(
context: CoroutineContext = EmptyCoroutineContext,
block: suspend CoroutineScope.() -> T
): T

View File

@ -0,0 +1,12 @@
package net.mamoe.mirai.utils.internal
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext
/**
* Mirror of `runBlocking` from `kotlinx.serialization` on JVM.
*/
internal actual fun <T> runBlocking(
context: CoroutineContext,
block: suspend CoroutineScope.() -> T
): T = kotlinx.coroutines.runBlocking(context, block)