From a54facea36ede6712a5eb2601d547042c499238d Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Fri, 3 May 2024 19:12:26 +0200 Subject: [PATCH] makes lazy modules & extension engine stable --- .../kotlin/org/koin/core/KoinApplicationLazyExt.kt | 2 -- .../src/commonMain/kotlin/org/koin/core/KoinLazyExt.kt | 4 ---- .../kotlin/org/koin/core/coroutine/KoinCoroutinesEngine.kt | 2 -- .../org/koin/core/extension/KoinCoroutinesExtension.kt | 3 --- .../commonMain/kotlin/org/koin/core/module/LazyModule.kt | 4 +++- .../commonMain/kotlin/org/koin/core/module/LazyModuleExt.kt | 6 ++++-- .../src/commonMain/kotlin/org/koin/dsl/LazyModuleDSL.kt | 3 --- .../kotlin/org/koin/mp/KoinPlatformCoroutinesTools.kt | 3 ++- 8 files changed, 9 insertions(+), 18 deletions(-) diff --git a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/KoinApplicationLazyExt.kt b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/KoinApplicationLazyExt.kt index 857b97083..4bb95da17 100644 --- a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/KoinApplicationLazyExt.kt +++ b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/KoinApplicationLazyExt.kt @@ -35,7 +35,6 @@ import org.koin.core.module.Module * * run coroutinesEngine() to setup if needed */ -@KoinExperimentalAPI fun KoinApplication.lazyModules(vararg moduleList: Lazy,dispatcher: CoroutineDispatcher? = null) { coroutinesEngine(dispatcher) koin.coroutinesEngine.launchStartJob { @@ -51,7 +50,6 @@ fun KoinApplication.lazyModules(vararg moduleList: Lazy,dispatcher: Coro * * run coroutinesEngine() to setup if needed */ -@KoinExperimentalAPI fun KoinApplication.lazyModules(moduleList: List>,dispatcher: CoroutineDispatcher? = null) { coroutinesEngine(dispatcher) koin.coroutinesEngine.launchStartJob { diff --git a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/KoinLazyExt.kt b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/KoinLazyExt.kt index d17d29086..c1d01e03a 100644 --- a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/KoinLazyExt.kt +++ b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/KoinLazyExt.kt @@ -15,7 +15,6 @@ */ package org.koin.core -import org.koin.core.annotation.KoinExperimentalAPI import org.koin.core.annotation.KoinInternalApi import org.koin.core.extension.coroutinesEngine @@ -27,7 +26,6 @@ import org.koin.core.extension.coroutinesEngine * Wait for Starting coroutines jobs to finish */ @OptIn(KoinInternalApi::class) -@KoinExperimentalAPI suspend fun Koin.awaitAllStartJobs() { coroutinesEngine.awaitAllStartJobs() } @@ -37,7 +35,6 @@ suspend fun Koin.awaitAllStartJobs() { * * @param block */ -@KoinExperimentalAPI suspend fun Koin.onKoinStarted(block: suspend (Koin) -> Unit) { awaitAllStartJobs() block(this) @@ -47,7 +44,6 @@ suspend fun Koin.onKoinStarted(block: suspend (Koin) -> Unit) { * Indicates if all start jobs have been done */ @OptIn(KoinInternalApi::class) -@KoinExperimentalAPI fun Koin.isAllStartedJobsDone(): Boolean { return coroutinesEngine.startJobs.all { !it.isActive } } diff --git a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/coroutine/KoinCoroutinesEngine.kt b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/coroutine/KoinCoroutinesEngine.kt index 3dd236010..28d9f6fb1 100644 --- a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/coroutine/KoinCoroutinesEngine.kt +++ b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/coroutine/KoinCoroutinesEngine.kt @@ -17,7 +17,6 @@ package org.koin.core.coroutine import kotlinx.coroutines.* import org.koin.core.Koin -import org.koin.core.annotation.KoinExperimentalAPI import org.koin.core.annotation.KoinInternalApi import org.koin.core.extension.KoinExtension import org.koin.core.logger.Logger @@ -31,7 +30,6 @@ import kotlin.coroutines.CoroutineContext * * @author Arnaud Giuliani */ -@KoinExperimentalAPI @KoinInternalApi class KoinCoroutinesEngine(coroutineDispatcher: CoroutineDispatcher? = null) : CoroutineScope, KoinExtension { private val dispatcher: CoroutineDispatcher = coroutineDispatcher ?: KoinPlatformCoroutinesTools.defaultCoroutineDispatcher() diff --git a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/extension/KoinCoroutinesExtension.kt b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/extension/KoinCoroutinesExtension.kt index 9c14b5484..740e12335 100644 --- a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/extension/KoinCoroutinesExtension.kt +++ b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/extension/KoinCoroutinesExtension.kt @@ -18,7 +18,6 @@ package org.koin.core.extension import kotlinx.coroutines.CoroutineDispatcher import org.koin.core.Koin import org.koin.core.KoinApplication -import org.koin.core.annotation.KoinExperimentalAPI import org.koin.core.annotation.KoinInternalApi import org.koin.core.coroutine.KoinCoroutinesEngine import org.koin.core.coroutine.KoinCoroutinesEngine.Companion.EXTENSION_NAME @@ -31,7 +30,6 @@ import org.koin.core.coroutine.KoinCoroutinesEngine.Companion.EXTENSION_NAME * Register KoinCoroutinesEngine extension */ @OptIn(KoinInternalApi::class) -@KoinExperimentalAPI fun KoinApplication.coroutinesEngine(dispatcher : CoroutineDispatcher? = null) { with(koin.extensionManager) { if (getExtensionOrNull(EXTENSION_NAME) == null) { @@ -41,5 +39,4 @@ fun KoinApplication.coroutinesEngine(dispatcher : CoroutineDispatcher? = null) { } @OptIn(KoinInternalApi::class) -@KoinExperimentalAPI val Koin.coroutinesEngine: KoinCoroutinesEngine get() = extensionManager.getExtension(EXTENSION_NAME) diff --git a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/module/LazyModule.kt b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/module/LazyModule.kt index 0e086b379..dcbe1f94e 100644 --- a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/module/LazyModule.kt +++ b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/module/LazyModule.kt @@ -21,8 +21,10 @@ package org.koin.core.module * Accepts a lambda that initializes a [Module] via [lazy()][lazy] * using [LazyThreadSafetyMode.NONE] as thread-safety [mode][LazyThreadSafetyMode]. * - * @author Chris Paleopanos * @param moduleInitializer a lambda that will be used to initialize a [Module] lazily + * + * @author Chris Paleopanos + * @author Arnaud Giuliani */ @KoinDslMarker class LazyModule(moduleInitializer: () -> Module) : Lazy by lazy(LazyThreadSafetyMode.NONE, moduleInitializer) { diff --git a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/module/LazyModuleExt.kt b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/module/LazyModuleExt.kt index 0dc190ef5..148f6d0c1 100644 --- a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/module/LazyModuleExt.kt +++ b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/core/module/LazyModuleExt.kt @@ -15,14 +15,16 @@ */ package org.koin.core.module -import org.koin.core.annotation.KoinExperimentalAPI import org.koin.core.annotation.KoinInternalApi +/** + * @author Arnaud Giuliani + */ + /** * Include list of `Lazy`, to be resolved only lazily */ @OptIn(KoinInternalApi::class) -@KoinExperimentalAPI fun Module.includes(vararg module: Lazy) { includedModules += module.map { it.value } } diff --git a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/dsl/LazyModuleDSL.kt b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/dsl/LazyModuleDSL.kt index 8b46746d7..895fbe359 100644 --- a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/dsl/LazyModuleDSL.kt +++ b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/dsl/LazyModuleDSL.kt @@ -15,10 +15,8 @@ */ package org.koin.dsl -import org.koin.core.annotation.KoinExperimentalAPI import org.koin.core.module.KoinDslMarker import org.koin.core.module.LazyModule -import org.koin.core.module.Module /** * Authors @@ -30,6 +28,5 @@ import org.koin.core.module.Module * * @See lazyModules() function, to load Lazy module in background */ -@KoinExperimentalAPI @KoinDslMarker fun lazyModule(moduleDefinition: ModuleDeclaration): LazyModule = LazyModule { module(moduleDeclaration = moduleDefinition) } diff --git a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/mp/KoinPlatformCoroutinesTools.kt b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/mp/KoinPlatformCoroutinesTools.kt index 83e592011..6351b4e8c 100644 --- a/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/mp/KoinPlatformCoroutinesTools.kt +++ b/projects/core/koin-core-coroutines/src/commonMain/kotlin/org/koin/mp/KoinPlatformCoroutinesTools.kt @@ -17,8 +17,9 @@ package org.koin.mp import kotlinx.coroutines.CoroutineDispatcher import org.koin.core.annotation.KoinExperimentalAPI +import org.koin.core.annotation.KoinInternalApi -@KoinExperimentalAPI +@KoinInternalApi expect object KoinPlatformCoroutinesTools { fun defaultCoroutineDispatcher(): CoroutineDispatcher }