Add context and start as params for safetyLaunch

This commit is contained in:
Kirill Nayduik 2021-08-24 09:51:04 +03:00
parent 64c4013f96
commit e29bb344fd
1 changed files with 9 additions and 2 deletions

View File

@ -1,10 +1,17 @@
package ru.touchin.extensions
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
fun CoroutineScope.safetyLaunch(block: suspend () -> Unit) {
launch {
fun CoroutineScope.safetyLaunch(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend () -> Unit
) {
launch(context, start) {
try {
block.invoke()
} catch (_: Throwable) { }