From 550fc59d9d0af82b3f74580241abd39410a5663b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 15:14:21 +0600 Subject: [PATCH 1/4] start 0.4.33 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cde6be0ffe..57848da8fc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.4.33 + ## 0.4.32 * `Versions`: diff --git a/gradle.properties b/gradle.properties index c7e30d18914..a6cfe2368b6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -44,5 +44,5 @@ dokka_version=1.4.30 # Project data group=dev.inmo -version=0.4.32 -android_code_version=36 +version=0.4.33 +android_code_version=37 From 36deab490998b3c8e125b79facb46420710f5b3f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 16:10:36 +0600 Subject: [PATCH 2/4] weak jobs workaround --- CHANGELOG.md | 4 ++ .../inmo/micro_utils/coroutines/WeakJob.kt | 31 ++++++++++++++ .../inmo/micro_utils/coroutines/WeakJob.kt | 40 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt create mode 100644 coroutines/src/jvmTest/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 57848da8fc0..3ccdc09591a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.4.33 +* `Coroutines` + * Add `WeakJob` workaround: + * `CoroutineScope#` + ## 0.4.32 * `Versions`: diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt new file mode 100644 index 00000000000..a11dc6b99ed --- /dev/null +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt @@ -0,0 +1,31 @@ +package dev.inmo.micro_utils.coroutines + +import kotlinx.coroutines.* +import kotlin.coroutines.CoroutineContext +import kotlin.coroutines.EmptyCoroutineContext + +fun CoroutineScope.createWeakSubScope() = CoroutineScope(coroutineContext.minusKey(Job)).also { newScope -> + coroutineContext.job.invokeOnCompletion { newScope.cancel() } +} + +fun CoroutineScope.weakLaunch( + context: CoroutineContext = EmptyCoroutineContext, + start: CoroutineStart = CoroutineStart.DEFAULT, + block: suspend CoroutineScope.() -> Unit +): Job { + val scope = createWeakSubScope() + val job = scope.launch(context, start, block) + job.invokeOnCompletion { scope.cancel() } + return job +} + +fun CoroutineScope.weakAsync( + context: CoroutineContext = EmptyCoroutineContext, + start: CoroutineStart = CoroutineStart.DEFAULT, + block: suspend CoroutineScope.() -> T +): Deferred { + val scope = createWeakSubScope() + val deferred = scope.async(context, start, block) + deferred.invokeOnCompletion { scope.cancel() } + return deferred +} diff --git a/coroutines/src/jvmTest/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt b/coroutines/src/jvmTest/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt new file mode 100644 index 00000000000..311b3b05b3b --- /dev/null +++ b/coroutines/src/jvmTest/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt @@ -0,0 +1,40 @@ +package dev.inmo.micro_utils.coroutines + +import kotlinx.coroutines.* +import org.junit.Test + +class WeakJob { + @Test + fun `test that weak jobs works correctly`() { + val scope = CoroutineScope(Dispatchers.Default) + lateinit var weakLaunchJob: Job + lateinit var weakAsyncJob: Job + scope.launchSynchronously { + val completeDeferred = Job() + coroutineScope { + weakLaunchJob = weakLaunch { + while (isActive) { + delay(100L) + } + } + weakAsyncJob = weakAsync { + while (isActive) { + delay(100L) + } + } + + coroutineContext.job.invokeOnCompletion { + scope.launch { + delay(1000L) + completeDeferred.complete() + } + } + launch { delay(1000L); cancel() } + } + completeDeferred.join() + } + + assert(!weakLaunchJob.isActive) + assert(!weakAsyncJob.isActive) + } +} From 382b956bebe77326a27f6c542fd9382bec14b62c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 16:20:11 +0600 Subject: [PATCH 3/4] make createWeakSubScope private, upfill readme --- CHANGELOG.md | 3 ++- .../kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ccdc09591a..74b429e3173 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ * `Coroutines` * Add `WeakJob` workaround: - * `CoroutineScope#` + * `CoroutineScope#weakLaunch` + * `CoroutineScope#weakAsync` ## 0.4.32 diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt index a11dc6b99ed..c020a359ecb 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/WeakJob.kt @@ -4,7 +4,7 @@ import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext -fun CoroutineScope.createWeakSubScope() = CoroutineScope(coroutineContext.minusKey(Job)).also { newScope -> +private fun CoroutineScope.createWeakSubScope() = CoroutineScope(coroutineContext.minusKey(Job)).also { newScope -> coroutineContext.job.invokeOnCompletion { newScope.cancel() } } From ce15ff4e0aa9a061ef600100d7829791c39724c8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 16:22:39 +0600 Subject: [PATCH 4/4] update ktor --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74b429e3173..f39632956be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.4.33 +* `Versions`: + * `Ktor`: `1.5.2` -> `1.5.3` * `Coroutines` * Add `WeakJob` workaround: * `CoroutineScope#weakLaunch` diff --git a/gradle.properties b/gradle.properties index a6cfe2368b6..a99d8f64d50 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ kotlin_coroutines_version=1.4.3 kotlin_serialisation_core_version=1.1.0 kotlin_exposed_version=0.30.1 -ktor_version=1.5.2 +ktor_version=1.5.3 klockVersion=2.0.7