mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-11-14 19:10:29 +00:00
add suspendPoint
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## 0.26.8
|
## 0.26.8
|
||||||
|
|
||||||
|
* `Coroutines`:
|
||||||
|
* Add simple suspend function `suspendPoint` which will ensure that current coroutine is active to let it be
|
||||||
|
destroyable even in case it have non-suspendable nature
|
||||||
|
|
||||||
## 0.26.7
|
## 0.26.7
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
|||||||
@@ -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