Compare commits

...

6 Commits

Author SHA1 Message Date
3bfe64f797 Update CHANGELOG.md 2024-06-20 01:53:42 +06:00
ec98029467 get back old function to break less API 2024-06-19 20:03:14 +06:00
ab58478686 Revert "fix of build"
This reverts commit 90247667d1.
2024-06-19 19:50:19 +06:00
90247667d1 fix of build 2024-06-19 19:50:00 +06:00
e661185534 fill changelog 2024-06-19 19:36:02 +06:00
d73e4e8e1f migrate onto 0.21.0 2024-06-19 19:30:16 +06:00
4 changed files with 45 additions and 10 deletions

View File

@@ -1,6 +1,13 @@
# Changelog
## 0.20.53
## 0.21.0
**THIS UPDATE CONTAINS BREAKING CHANGES IN `safely*`-ORIENTED FUNCTIONS**
* `Coroutines`:
* **All `safely` functions lost their `supervisorScope` in favor to wrapping `runCatching`**
* `runCatchingSafely` is the main handling function of all `safely` functions
* `launchSafely*` and `asyncSafely*` blocks lost `CoroutineScope` as their receiver
## 0.20.52

View File

@@ -29,6 +29,13 @@ suspend inline fun <T> runCatchingSafely(
}
}
suspend inline fun <T, R> R.runCatchingSafely(
onException: ExceptionHandler<T>,
block: suspend R.() -> T
): Result<T> = runCatchingSafely<T>(onException) {
block()
}
/**
* Launching [runCatchingSafely] with [defaultSafelyExceptionHandler] as `onException` parameter
*/
@@ -36,6 +43,12 @@ suspend inline fun <T> runCatchingSafely(
block: suspend () -> T
): Result<T> = runCatchingSafely(defaultSafelyExceptionHandler, block)
suspend inline fun <T, R> R.runCatchingSafely(
block: suspend R.() -> T
): Result<T> = runCatchingSafely<T> {
block()
}
//suspend inline fun <T, R> T.runCatchingSafely(
// onException: ExceptionHandler<R>,
// block: suspend T.() -> R
@@ -94,11 +107,18 @@ suspend inline fun <T> safely(
suspend inline fun <T> safely(
block: suspend () -> T
): T = safely(defaultSafelyExceptionHandler, block)
suspend inline fun <T, R> R.safely(
block: suspend R.() -> T
): T = safely<T> { block() }
@Deprecated("Renamed", ReplaceWith("runCatchingSafely(block)", "dev.inmo.micro_utils.coroutines.runCatchingSafely"))
suspend fun <T> safelyWithResult(
block: suspend () -> T
): Result<T> = runCatchingSafely(defaultSafelyExceptionHandler, block)
@Deprecated("Renamed", ReplaceWith("this.runCatchingSafely(block)", "dev.inmo.micro_utils.coroutines.runCatchingSafely"))
suspend fun <T, R> R.safelyWithResult(
block: suspend R.() -> T
): Result<T> = safelyWithResult<T> { block() }
/**
* Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and

View File

@@ -8,34 +8,42 @@ fun CoroutineScope.launchSafely(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler,
block: suspend () -> Unit
block: suspend CoroutineScope.() -> Unit
) = launch(context, start) {
runCatchingSafely(onException, block = block)
runCatchingSafely(onException) {
block()
}
}
fun CoroutineScope.launchSafelyWithoutExceptions(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
onException: ExceptionHandler<Unit?> = defaultSafelyWithoutExceptionHandlerWithNull,
block: suspend () -> Unit
block: suspend CoroutineScope.() -> Unit
) = launch(context, start) {
runCatchingSafelyWithoutExceptions(onException, block = block)
runCatchingSafelyWithoutExceptions(onException) {
block()
}
}
fun <T> CoroutineScope.asyncSafely(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
onException: ExceptionHandler<T> = defaultSafelyExceptionHandler,
block: suspend () -> T
block: suspend CoroutineScope.() -> T
) = async(context, start) {
runCatchingSafely(onException, block = block)
runCatchingSafely(onException) {
block()
}
}
fun <T> CoroutineScope.asyncSafelyWithoutExceptions(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull,
block: suspend () -> T
block: suspend CoroutineScope.() -> T
) = async(context, start) {
runCatchingSafelyWithoutExceptions(onException, block = block)
runCatchingSafelyWithoutExceptions(onException) {
block()
}
}

View File

@@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.20.53
version=0.21.0
android_code_version=259