From f412d387fa590fb8a01a2de3ac5a27d788efb74b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 29 Jul 2023 16:05:24 +0600 Subject: [PATCH 1/4] start 0.19.9 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 062c40c4bdf..9b7b51f2287 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.19.9 + ## 0.19.8 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 7829fb7f8de..9071ebce7f9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.19.8 -android_code_version=204 +version=0.19.9 +android_code_version=205 From f081e237c827373e6c7c42a3e86abf5def9a07f6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 29 Jul 2023 16:30:17 +0600 Subject: [PATCH 2/4] improvements in startup plugin --- .../commonMain/kotlin/StartLauncherPlugin.kt | 86 ++++++++++++++++--- 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/startup/launcher/src/commonMain/kotlin/StartLauncherPlugin.kt b/startup/launcher/src/commonMain/kotlin/StartLauncherPlugin.kt index 47bc9e3d928..5074b69a944 100644 --- a/startup/launcher/src/commonMain/kotlin/StartLauncherPlugin.kt +++ b/startup/launcher/src/commonMain/kotlin/StartLauncherPlugin.kt @@ -9,10 +9,7 @@ import dev.inmo.micro_utils.koin.annotations.GenerateKoinDefinition import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.setupDI import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.startPlugin import dev.inmo.micro_utils.startup.plugin.StartPlugin -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.joinAll -import kotlinx.coroutines.launch +import kotlinx.coroutines.* import kotlinx.serialization.SerialFormat import kotlinx.serialization.StringFormat import kotlinx.serialization.json.Json @@ -116,12 +113,16 @@ object StartLauncherPlugin : StartPlugin { /** * Will create [KoinApplication], init, load modules using [StartLauncherPlugin] and start plugins using the same base * plugin. It is basic [start] method which accepts both [config] and [rawConfig] which suppose to be the same or - * at least [rawConfig] must contain serialized variant of [config] + * at least [rawConfig] must contain serialized variant of [config]. + * + * Koin part will be started in-place. This means, that after ending of this method call you will be able to + * take any declared dependency from koin * * @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] ([StartLauncherPlugin] will * deserialize it in its [StartLauncherPlugin.setupDI] + * @return [KoinApplication] of current start and [Job] which can be used to call [CoroutineScope.join] */ - suspend fun start(config: Config, rawConfig: JsonObject) { + fun startAsync(config: Config, rawConfig: JsonObject): Pair { logger.i("Start initialization") val koinApp = KoinApplication.init() @@ -133,8 +134,44 @@ object StartLauncherPlugin : StartPlugin { logger.i("Modules loaded") startKoin(koinApp) logger.i("Koin started") - startPlugin(koinApp.koin) - logger.i("App has been setup") + val launchJob = koinApp.koin.get().launch { + startPlugin(koinApp.koin) + logger.i("App has been started") + } + + return koinApp to launchJob + } + + /** + * Will create [KoinApplication], init, load modules using [StartLauncherPlugin] and start plugins using the same base + * plugin. It is basic [start] method which accepts both [config] and [rawConfig] which suppose to be the same or + * at least [rawConfig] must contain serialized variant of [config] + * + * @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] ([StartLauncherPlugin] will + * deserialize it in its [StartLauncherPlugin.setupDI] + * @return [KoinApplication] of current launch + */ + suspend fun start(config: Config, rawConfig: JsonObject): KoinApplication { + + val (koinApp, job) = startAsync(config, rawConfig) + + job.join() + + return koinApp + } + + /** + * Call [start] with deserialized [Config] as config and [rawConfig] as is + * + * Koin part will be started in-place. This means, that after ending of this method call you will be able to + * take any declared dependency from koin + * + * @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] + * @return [KoinApplication] of current launch and [Job] of starting launch + */ + fun startAsync(rawConfig: JsonObject): Pair { + + return startAsync(defaultJson.decodeFromJsonElement(Config.serializer(), rawConfig), rawConfig) } @@ -143,9 +180,30 @@ object StartLauncherPlugin : StartPlugin { * * @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] */ - suspend fun start(rawConfig: JsonObject) { + suspend fun start(rawConfig: JsonObject): KoinApplication { - start(defaultJson.decodeFromJsonElement(Config.serializer(), rawConfig), rawConfig) + val (koinApp, job) = startAsync(rawConfig) + + job.join() + + return koinApp + + } + + /** + * Call [start] with deserialized [Config] as is and serialize it to [JsonObject] to pass as the first parameter + * to the basic [start] method + * + * Koin part will be started in-place. This means, that after ending of this method call you will be able to + * take any declared dependency from koin + * + * @param config Will be converted to [JsonObject] as raw config. That means that all plugins from [config] will + * receive serialized version of [config] in [StartPlugin.setupDI] method + * @return [KoinApplication] of current launch and [Job] of starting launch + */ + fun startAsync(config: Config): Pair { + + return startAsync(config, defaultJson.encodeToJsonElement(Config.serializer(), config).jsonObject) } @@ -156,9 +214,13 @@ object StartLauncherPlugin : StartPlugin { * @param config Will be converted to [JsonObject] as raw config. That means that all plugins from [config] will * receive serialized version of [config] in [StartPlugin.setupDI] method */ - suspend fun start(config: Config) { + suspend fun start(config: Config): KoinApplication { - start(config, defaultJson.encodeToJsonElement(Config.serializer(), config).jsonObject) + val (koinApp, job) = startAsync(config) + + job.join() + + return koinApp } } From a169e733d9da0fa480ce2e3fab750b39ea93d2e1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 29 Jul 2023 16:31:50 +0600 Subject: [PATCH 3/4] fill changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b7b51f2287..44903aa4816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.19.9 +* `Startup`: + * Now it is possible to start application in synchronous way + ## 0.19.8 * `Versions`: From 4d155d0505dc5577aa078704c0baf1ed3926f015 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 29 Jul 2023 16:37:25 +0600 Subject: [PATCH 4/4] update koin --- CHANGELOG.md | 2 ++ gradle/libs.versions.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44903aa4816..5f3919a93e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.19.9 +* `Versions`: + * `Koin`: `3.4.2` -> `3.4.3` * `Startup`: * Now it is possible to start application in synchronous way diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c1c1b8b9ec6..ec9777eb8bc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,7 +17,7 @@ ktor = "2.3.2" gh-release = "2.4.1" -koin = "3.4.2" +koin = "3.4.3" okio = "3.4.0"