launchSynchronously signature update

This commit is contained in:
InsanusMokrassar 2020-12-14 20:06:46 +06:00
parent a60cb596d1
commit 46bfb09415
2 changed files with 6 additions and 2 deletions

View File

@ -2,6 +2,8 @@
## 0.4.12 ## 0.4.12
* `Coroutines`
* Update `launchSynchronously` signature
* `Selector` * `Selector`
* Project created * Project created

View File

@ -2,12 +2,12 @@ package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.* import kotlinx.coroutines.*
fun <T> launchSynchronously(scope: CoroutineScope = CoroutineScope(Dispatchers.Default), block: suspend CoroutineScope.() -> T): T { fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T {
var throwable: Throwable? = null var throwable: Throwable? = null
var result: T? = null var result: T? = null
val objectToSynchronize = java.lang.Object() val objectToSynchronize = java.lang.Object()
val launchCallback = { val launchCallback = {
scope.launch { launch {
safely( safely(
{ {
throwable = it throwable = it
@ -26,3 +26,5 @@ fun <T> launchSynchronously(scope: CoroutineScope = CoroutineScope(Dispatchers.D
} }
throw throwable ?: return result!! throw throwable ?: return result!!
} }
fun <T> launchSynchronously(block: suspend CoroutineScope.() -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block)