mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-10-22 15:50:34 +00:00
alsoInvalidate, alsoDoInvalidate, singleSuspend, factorySuspend
This commit is contained in:
32
koin/src/jvmMain/kotlin/FactorySuspend.kt
Normal file
32
koin/src/jvmMain/kotlin/FactorySuspend.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package dev.inmo.micro_utils.koin
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.doSynchronously
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.parameter.ParametersHolder
|
||||
import org.koin.core.qualifier.Qualifier
|
||||
import org.koin.core.qualifier.StringQualifier
|
||||
import org.koin.core.scope.Scope
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
inline fun <reified T : Any> Module.factorySuspend(
|
||||
qualifier: Qualifier? = null,
|
||||
coroutineScope: CoroutineScope? = null,
|
||||
noinline definition: suspend Scope.(ParametersHolder) -> T
|
||||
) = factory(
|
||||
qualifier,
|
||||
if (coroutineScope == null) {
|
||||
{
|
||||
doSynchronously {
|
||||
definition(it)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
{
|
||||
coroutineScope.doSynchronously {
|
||||
definition(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
32
koin/src/jvmMain/kotlin/SingleSuspend.kt
Normal file
32
koin/src/jvmMain/kotlin/SingleSuspend.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package dev.inmo.micro_utils.koin
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.doSynchronously
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.parameter.ParametersHolder
|
||||
import org.koin.core.qualifier.StringQualifier
|
||||
import org.koin.core.scope.Scope
|
||||
|
||||
inline fun <reified T : Any> Module.singleSuspend(
|
||||
qualifier: StringQualifier,
|
||||
createdAtStart: Boolean = false,
|
||||
coroutineScope: CoroutineScope? = null,
|
||||
noinline definition: suspend Scope.(ParametersHolder) -> T
|
||||
) = single(
|
||||
qualifier,
|
||||
createdAtStart,
|
||||
if (coroutineScope == null) {
|
||||
{
|
||||
doSynchronously {
|
||||
definition(it)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
{
|
||||
coroutineScope.doSynchronously {
|
||||
definition(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user