mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-13 19:37:00 +05:30
coroutine-utils: init
This commit is contained in:
parent
8986ad246a
commit
1db2f3256d
3 changed files with 30 additions and 0 deletions
9
coroutine-utils/build.gradle.kts
Normal file
9
coroutine-utils/build.gradle.kts
Normal file
|
@ -0,0 +1,9 @@
|
|||
plugins {
|
||||
kotlin("jvm")
|
||||
id("dev.msfjarvis.claw.kotlin-library")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(libs.kotlinx.coroutines.core)
|
||||
implementation(libs.dagger.hilt.core)
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package dev.msfjarvis.claw.util.coroutines
|
||||
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
|
||||
/** Interface to allow abstracting individual [CoroutineDispatcher]s out of class dependencies. */
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
interface DispatcherProvider {
|
||||
|
||||
fun main(): CoroutineDispatcher = Dispatchers.Main
|
||||
fun default(): CoroutineDispatcher = Dispatchers.Default
|
||||
fun io(): CoroutineDispatcher = Dispatchers.IO
|
||||
fun unconfined(): CoroutineDispatcher = Dispatchers.Unconfined
|
||||
fun database(): CoroutineDispatcher = Dispatchers.IO.limitedParallelism(1)
|
||||
}
|
||||
|
||||
/** Concrete type for [DispatcherProvider] with all the defaults from the class. */
|
||||
class DefaultDispatcherProvider @Inject constructor() : DispatcherProvider
|
|
@ -106,6 +106,7 @@ include(
|
|||
"api",
|
||||
"benchmark",
|
||||
"common",
|
||||
"coroutine-utils",
|
||||
"database",
|
||||
"metadata-extractor",
|
||||
"model",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue