mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
commit
98bd07d025
@ -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`
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user