Compare commits

...

11 Commits
0.5.4 ... 0.5.6

Author SHA1 Message Date
2a2da21ff3 fillup safelyWithResult 2021-06-05 15:18:48 +06:00
04ef371337 update safelyWithResult 2021-06-05 15:18:09 +06:00
623e0cd369 improve launchSynchronously 2021-06-05 15:16:07 +06:00
1f466747f0 update exposed 2021-06-05 15:08:22 +06:00
2215462f99 start 0.5.6 2021-06-05 15:07:27 +06:00
ac4c0a2e4c Merge pull request #69 from InsanusMokrassar/0.5.5
0.5.5
2021-05-28 23:50:35 +06:00
f7496db5ac Update CHANGELOG.md 2021-05-28 19:34:30 +06:00
3028fe975d Update ktor 2021-05-28 19:33:02 +06:00
23a5034493 start 0.5.5 2021-05-28 19:32:04 +06:00
65e339f811 Merge pull request #68 from InsanusMokrassar/0.5.4
0.5.4
2021-05-26 22:33:53 +06:00
a00d734712 Merge pull request #67 from InsanusMokrassar/0.5.4
0.5.4
2021-05-26 22:07:28 +06:00
4 changed files with 31 additions and 19 deletions

View File

@@ -1,5 +1,19 @@
# Changelog # Changelog
## 0.5.6
* `Versions`
* `Exposed`: `0.31.1` -> `0.32.1`
* `Coroutines`
* `JVM`
* `launchSynchronously` and subsequent functions got improved mechanism
* New method `safelyWithResult`
## 0.5.5
* `Versions`
* `Ktor`: `1.5.4` -> `1.6.0`
## 0.5.4 ## 0.5.4
* `Versions`: * `Versions`:

View File

@@ -115,6 +115,10 @@ suspend inline fun <T> runCatchingSafely(
safely(onException, block) safely(onException, block)
} }
suspend inline fun <T> safelyWithResult(
noinline block: suspend CoroutineScope.() -> T
): Result<T> = runCatchingSafely(defaultSafelyExceptionHandler, block)
/** /**
* Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and * Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and
* returning null at one time * returning null at one time

View File

@@ -3,27 +3,21 @@ package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.* import kotlinx.coroutines.*
fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T { fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T {
val deferred = CompletableDeferred<T>() var result: Result<T>? = null
val objectToSynchronize = java.lang.Object() val objectToSynchronize = Object()
val launchCallback = { synchronized(objectToSynchronize) {
launch { launch {
safely( result = safelyWithResult(block)
{ }.invokeOnCompletion {
deferred.completeExceptionally(it)
}
) {
deferred.complete(block())
}
synchronized(objectToSynchronize) { synchronized(objectToSynchronize) {
objectToSynchronize.notifyAll() objectToSynchronize.notifyAll()
} }
} }
while (result == null) {
objectToSynchronize.wait()
}
} }
synchronized(objectToSynchronize) { return result!!.getOrThrow()
launchCallback()
objectToSynchronize.wait()
}
return deferred.getCompleted()
} }
fun <T> launchSynchronously(block: suspend CoroutineScope.() -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block) fun <T> launchSynchronously(block: suspend CoroutineScope.() -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block)

View File

@@ -10,9 +10,9 @@ org.gradle.jvmargs=-Xmx2g
kotlin_version=1.5.10 kotlin_version=1.5.10
kotlin_coroutines_version=1.5.0 kotlin_coroutines_version=1.5.0
kotlin_serialisation_core_version=1.2.1 kotlin_serialisation_core_version=1.2.1
kotlin_exposed_version=0.31.1 kotlin_exposed_version=0.32.1
ktor_version=1.5.4 ktor_version=1.6.0
klockVersion=2.1.2 klockVersion=2.1.2
@@ -45,5 +45,5 @@ dokka_version=1.4.32
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.5.4 version=0.5.6
android_code_version=45 android_code_version=47