-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checked for memory leaks using 'leaks' tool.
- Loading branch information
1 parent
d8ba9f1
commit 696499a
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/coroutines.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.smyrgeorge.sqlx4k | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.IO | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
import kotlinx.coroutines.withContext | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
@Suppress("unused") | ||
suspend fun <A, B> Iterable<A>.mapParallel(context: CoroutineContext = Dispatchers.IO, f: suspend (A) -> B): List<B> = | ||
withContext(context) { map { async { f(it) } }.awaitAll() } | ||
|
||
suspend fun <A> Iterable<A>.forEachParallel(context: CoroutineContext = Dispatchers.IO, f: suspend (A) -> Unit): Unit = | ||
withContext(context) { map { async { f(it) } }.awaitAll() } | ||
|