mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-09 09:06:59 +08:00
Add common runBlocking
for convenience
This commit is contained in:
parent
a69d6e2ecd
commit
d9756c212c
@ -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)
|
@ -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
|
@ -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)
|
Loading…
Reference in New Issue
Block a user