Skip to content

Commit

Permalink
[NFC] Document MonoTasker on thread safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Feb 8, 2025
1 parent 4220a4b commit a58a7a4
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
* Copyright (C) 2024-2025 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
Expand Down Expand Up @@ -32,16 +32,25 @@ import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

/**
* Note: This function is not thread safe. For thread-safe variant, you may consider `SingleTaskExecutor`.
*/
@Stable
interface MonoTasker {
val isRunning: StateFlow<Boolean>

/**
* Note: This function is not thread safe.
*/
fun launch(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> Unit
): Job

/**
* Note: This function is not thread safe.
*/
fun <R> async(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
Expand All @@ -50,17 +59,28 @@ interface MonoTasker {

/**
* 等待上一个任务完成后再执行
*
* Note: This function is not thread safe.
*/
fun launchNext(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> Unit
)

/**
* Note: This function is not thread safe.
*/
fun cancel(cause: CancellationException? = null)

/**
* Note: This function is not thread safe.
*/
suspend fun cancelAndJoin()

/**
* Note: This function is not thread safe.
*/
suspend fun join()
}

Expand Down

0 comments on commit a58a7a4

Please sign in to comment.