new: integrate a dispatcher provider and dispatch work
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.kotlinMultiplatform)
|
||||
alias(libs.plugins.androidMultiplatformLibrary)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
iosArm64()
|
||||
iosSimulatorArm64()
|
||||
|
||||
jvm()
|
||||
|
||||
js {
|
||||
browser()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalWasmDsl::class)
|
||||
wasmJs {
|
||||
browser()
|
||||
}
|
||||
|
||||
androidLibrary {
|
||||
namespace = "fr.ajaury.gwenedeg.core.coroutines"
|
||||
compileSdk =
|
||||
libs.versions.androidCompileSdk
|
||||
.get()
|
||||
.toInt()
|
||||
minSdk =
|
||||
libs.versions.androidMinSdk
|
||||
.get()
|
||||
.toInt()
|
||||
|
||||
compilerOptions {
|
||||
jvmTarget = JvmTarget.JVM_11
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
// Coroutines
|
||||
implementation(libs.kotlinx.coroutinesCore)
|
||||
|
||||
// DI
|
||||
implementation(project.dependencies.platform(libs.koin.bom))
|
||||
implementation(libs.koin.core)
|
||||
}
|
||||
commonTest.dependencies {
|
||||
implementation(libs.kotlin.test)
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
internal actual val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.data
|
||||
|
||||
import fr.ajaury.gwenedeg.core.coroutines.domain.DispatcherProvider
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
internal class DefaultDispatcherProvider : DispatcherProvider {
|
||||
override val main: CoroutineDispatcher = Dispatchers.Main
|
||||
override val default: CoroutineDispatcher = Dispatchers.Default
|
||||
override val io: CoroutineDispatcher = ioDispatcher
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
|
||||
internal expect val ioDispatcher: CoroutineDispatcher
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.di
|
||||
|
||||
import fr.ajaury.gwenedeg.core.coroutines.data.DefaultDispatcherProvider
|
||||
import fr.ajaury.gwenedeg.core.coroutines.domain.DispatcherProvider
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.module
|
||||
|
||||
val coroutinesModule: Module = module {
|
||||
single<DispatcherProvider> { DefaultDispatcherProvider() }
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.domain
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
|
||||
interface DispatcherProvider {
|
||||
val main: CoroutineDispatcher
|
||||
val default: CoroutineDispatcher
|
||||
val io: CoroutineDispatcher
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
// `Dispatchers.IO` is not public API on Native; `Dispatchers.Default` is multi-threaded here, so it
|
||||
// still runs work off the main thread.
|
||||
internal actual val ioDispatcher: CoroutineDispatcher = Dispatchers.Default
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
// JS is single-threaded; there is no dedicated I/O dispatcher, use default.
|
||||
internal actual val ioDispatcher: CoroutineDispatcher = Dispatchers.Default
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
internal actual val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package fr.ajaury.gwenedeg.core.coroutines.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
// Wasm is single-threaded; there is no dedicated I/O dispatcher, use default
|
||||
internal actual val ioDispatcher: CoroutineDispatcher = Dispatchers.Default
|
||||
Reference in New Issue
Block a user