Merge pull request #50 from InsanusMokrassar/0.4.28

0.4.28
This commit is contained in:
InsanusMokrassar 2021-03-02 01:09:48 +06:00 committed by GitHub
commit 98bd07d025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 12 deletions

View File

@ -1,5 +1,13 @@
# Changelog
## 0.4.28
* `Versions`:
* `Kotlin`: `1.4.30` -> `1.4.31`
* `Ktor`: `1.5.1` -> `1.5.2`
* `Coroutines`
* Add `createActionsActor`/`createSafeActionsActor` and `doWithSuspending`
## 0.4.27
* `Repos`

View File

@ -0,0 +1,46 @@
package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
import kotlin.coroutines.*
interface ActorAction<T> {
suspend operator fun invoke(): T
}
/**
* Planned to use with [doWithSuspending]. Will execute incoming lambdas sequentially
*
* @see actor
*/
fun CoroutineScope.createActionsActor() = actor<suspend () -> Unit> {
it()
}
/**
* Planned to use with [doWithSuspending]. Will execute incoming lambdas sequentially
*
* @see safeActor
*/
inline fun CoroutineScope.createSafeActionsActor(
noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler
) = safeActor<suspend () -> 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 <T> Channel<suspend () -> Unit>.doWithSuspending(
action: ActorAction<T>
) = suspendCoroutine<T> {
offer {
safely({ e -> it.resumeWithException(e) }) {
it.resume(action())
}
}
}

View File

@ -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
@ -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

View File

@ -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(