mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-11-14 19:10:29 +00:00
add suspendPoint
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package dev.inmo.micro_utils.coroutines
|
||||
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.ensureActive
|
||||
|
||||
/**
|
||||
* Ensures that the current coroutine context is still active and throws a [kotlinx.coroutines.CancellationException]
|
||||
* if the coroutine has been canceled.
|
||||
*
|
||||
* This function provides a convenient way to check the active status of a coroutine, which is useful
|
||||
* to identify cancellation points in long-running or suspendable operations.
|
||||
*
|
||||
* @throws kotlinx.coroutines.CancellationException if the coroutine context is no longer active.
|
||||
*/
|
||||
suspend fun suspendPoint() = currentCoroutineContext().ensureActive()
|
||||
Reference in New Issue
Block a user