From 4b83ca19c3e4a18c4945b4bfed363287383298db Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 1 Mar 2021 18:21:34 +0600 Subject: [PATCH 1/4] start 0.4.28 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3794730e54f..1713ad5b2c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.4.28 + ## 0.4.27 * `Repos` diff --git a/gradle.properties b/gradle.properties index 9f8ad7e19c9..ef84fd589e5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -44,5 +44,5 @@ dokka_version=1.4.20 # Project data group=dev.inmo -version=0.4.27 -android_code_version=31 +version=0.4.28 +android_code_version=32 From 42594f06565fe168217da535b89be2cc42120cac Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 1 Mar 2021 18:23:20 +0600 Subject: [PATCH 2/4] update dependencies --- CHANGELOG.md | 4 ++++ gradle.properties | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1713ad5b2c2..5990de4f722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.4.28 +* `Versions`: + * `Kotlin`: `1.4.30` -> `1.4.31` + * `Ktor`: `1.5.1` -> `1.5.2` + ## 0.4.27 * `Repos` diff --git a/gradle.properties b/gradle.properties index ef84fd589e5..5bac5c44c53 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,12 +6,12 @@ kotlin.incremental.js=true android.useAndroidX=true android.enableJetifier=true -kotlin_version=1.4.30 +kotlin_version=1.4.31 kotlin_coroutines_version=1.4.2 kotlin_serialisation_core_version=1.1.0 kotlin_exposed_version=0.29.1 -ktor_version=1.5.1 +ktor_version=1.5.2 klockVersion=2.0.6 From d933dc532b1684f568d56be4fe68b187857e2e50 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 1 Mar 2021 18:35:11 +0600 Subject: [PATCH 3/4] add actions actor --- CHANGELOG.md | 2 + .../micro_utils/coroutines/ActionsActor.kt | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/ActionsActor.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 5990de4f722..dd6045f7252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * `Versions`: * `Kotlin`: `1.4.30` -> `1.4.31` * `Ktor`: `1.5.1` -> `1.5.2` +* `Coroutines` + * Add `createActionsActor`/`createSafeActionsActor` and `doWithSuspending` ## 0.4.27 diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/ActionsActor.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/ActionsActor.kt new file mode 100644 index 00000000000..9a22f9f1cfe --- /dev/null +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/ActionsActor.kt @@ -0,0 +1,46 @@ +package dev.inmo.micro_utils.coroutines + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.channels.Channel +import kotlin.coroutines.* + +interface ActorAction { + suspend operator fun invoke(): T +} + +/** + * Planned to use with [doWithSuspending]. Will execute incoming lambdas sequentially + * + * @see actor + */ +fun CoroutineScope.createActionsActor() = actor Unit> { + it() +} + +/** + * Planned to use with [doWithSuspending]. Will execute incoming lambdas sequentially + * + * @see safeActor + */ +inline fun CoroutineScope.createSafeActionsActor( + noinline onException: ExceptionHandler = defaultSafelyExceptionHandler +) = safeActor Unit>(Channel.UNLIMITED, onException) { + it() +} + +/** + * Must be use with actor created by [createActionsActor] or [createSafeActionsActor]. Will send lambda which will + * execute [action] and return result. + * + * @see suspendCoroutine + * @see safely + */ +suspend fun Channel Unit>.doWithSuspending( + action: ActorAction +) = suspendCoroutine { + offer { + safely({ e -> it.resumeWithException(e) }) { + it.resume(action()) + } + } +} From c502c70a21aa35db982904e2d9c92c98c46d68c3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 2 Mar 2021 00:54:21 +0600 Subject: [PATCH 4/4] should fix lint errors --- .../micro_utils/repos/DatabaseOperations.kt | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/DatabaseOperations.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/DatabaseOperations.kt index b1cfdb28804..35b04fa0c4b 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/DatabaseOperations.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/DatabaseOperations.kt @@ -26,20 +26,39 @@ fun SQLiteDatabase.createTable( } } -fun Cursor.getString(columnName: String) = getString( - getColumnIndex(columnName) +/** + * @throws IllegalArgumentException + */ +fun Cursor.getString(columnName: String): String = getString( + getColumnIndexOrThrow(columnName) ) -fun Cursor.getLong(columnName: String) = getLong( - getColumnIndex(columnName) +/** + * @throws IllegalArgumentException + */ +fun Cursor.getShort(columnName: String): Short = getShort( + getColumnIndexOrThrow(columnName) ) -fun Cursor.getInt(columnName: String) = getInt( - getColumnIndex(columnName) +/** + * @throws IllegalArgumentException + */ +fun Cursor.getLong(columnName: String): Long = getLong( + getColumnIndexOrThrow(columnName) ) -fun Cursor.getDouble(columnName: String) = getDouble( - getColumnIndex(columnName) +/** + * @throws IllegalArgumentException + */ +fun Cursor.getInt(columnName: String): Int = getInt( + getColumnIndexOrThrow(columnName) +) + +/** + * @throws IllegalArgumentException + */ +fun Cursor.getDouble(columnName: String): Double = getDouble( + getColumnIndexOrThrow(columnName) ) fun SQLiteDatabase.select(