Skip to content

Commit b7b6be1

Browse files
committed
Coroutines: Give concurrent jobs proper scope
1 parent d3b6202 commit b7b6be1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/kotlin/com/lambda/threading/Threading.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.lambda.context.SafeContext
2323
import com.lambda.event.EventFlow
2424
import com.mojang.blaze3d.systems.RenderSystem.isOnRenderThread
2525
import kotlinx.coroutines.CoroutineDispatcher
26+
import kotlinx.coroutines.CoroutineScope
2627
import kotlinx.coroutines.Dispatchers
2728
import kotlinx.coroutines.future.await
2829
import kotlinx.coroutines.launch
@@ -52,17 +53,17 @@ inline fun <T> runSafe(block: SafeContext.() -> T) =
5253
*
5354
* @param block The block of code to be executed concurrently.
5455
*/
55-
inline fun runConcurrent(scheduler: CoroutineDispatcher = Dispatchers.Default, crossinline block: suspend () -> Unit) =
56+
inline fun runConcurrent(scheduler: CoroutineDispatcher = Dispatchers.Default, crossinline block: suspend CoroutineScope.() -> Unit) =
5657
EventFlow.lambdaScope.launch(scheduler) {
5758
block()
5859
}
5960

60-
inline fun runIO(crossinline block: suspend () -> Unit) =
61+
inline fun runIO(crossinline block: suspend CoroutineScope.() -> Unit) =
6162
runConcurrent(Dispatchers.IO) {
6263
block()
6364
}
6465

65-
inline fun taskContext(crossinline block: suspend () -> Unit) =
66+
inline fun taskContext(crossinline block: suspend CoroutineScope.() -> Unit) =
6667
EventFlow.lambdaScope.launch {
6768
block()
6869
}

0 commit comments

Comments
 (0)