Skip to content

Commit

Permalink
Checked for memory leaks using 'leaks' tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
smyrgeorge committed Jun 24, 2024
1 parent d8ba9f1 commit 696499a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/coroutines.kt
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() }

0 comments on commit 696499a

Please sign in to comment.