Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makes lazy modules & extension engine stable #1868

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import org.koin.core.module.Module
*
* run coroutinesEngine() to setup if needed
*/
@KoinExperimentalAPI
fun KoinApplication.lazyModules(vararg moduleList: Lazy<Module>,dispatcher: CoroutineDispatcher? = null) {
coroutinesEngine(dispatcher)
koin.coroutinesEngine.launchStartJob {
Expand All @@ -51,7 +50,6 @@ fun KoinApplication.lazyModules(vararg moduleList: Lazy<Module>,dispatcher: Coro
*
* run coroutinesEngine() to setup if needed
*/
@KoinExperimentalAPI
fun KoinApplication.lazyModules(moduleList: List<Lazy<Module>>,dispatcher: CoroutineDispatcher? = null) {
coroutinesEngine(dispatcher)
koin.coroutinesEngine.launchStartJob {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
}
Expand All @@ -37,7 +35,6 @@ suspend fun Koin.awaitAllStartJobs() {
*
* @param block
*/
@KoinExperimentalAPI
suspend fun Koin.onKoinStarted(block: suspend (Koin) -> Unit) {
awaitAllStartJobs()
block(this)
Expand All @@ -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 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<KoinCoroutinesEngine>(EXTENSION_NAME) == null) {
Expand All @@ -41,5 +39,4 @@ fun KoinApplication.coroutinesEngine(dispatcher : CoroutineDispatcher? = null) {
}

@OptIn(KoinInternalApi::class)
@KoinExperimentalAPI
val Koin.coroutinesEngine: KoinCoroutinesEngine get() = extensionManager.getExtension(EXTENSION_NAME)
Original file line number Diff line number Diff line change
Expand Up @@ -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<Module> by lazy(LazyThreadSafetyMode.NONE, moduleInitializer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Module>`, to be resolved only lazily
*/
@OptIn(KoinInternalApi::class)
@KoinExperimentalAPI
fun Module.includes(vararg module: Lazy<Module>) {
includedModules += module.map { it.value }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
Original file line number Diff line number Diff line change
Expand Up @@ -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
}