mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
launchSynchronously signature update
This commit is contained in:
parent
a60cb596d1
commit
46bfb09415
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## 0.4.12
|
## 0.4.12
|
||||||
|
|
||||||
|
* `Coroutines`
|
||||||
|
* Update `launchSynchronously` signature
|
||||||
* `Selector`
|
* `Selector`
|
||||||
* Project created
|
* Project created
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user