darkmoon_uk
02/21/2023, 4:33 AMfun load() = scope.launch {
...
}.ignore()
where .ignore() returns Unit vs.
(2)
fun load() {
scope.launch {
...
}
}
Vote 1️⃣ or 2️⃣ephemient
02/21/2023, 5:32 AM.let {} is built-in .ignore()ephemient
02/21/2023, 5:36 AMinfix fun <T, U> T.withSideEffect(ignored: U): T = this
fun load() = Unit withSideEffect scope.launch {
...
}
but I think that's total overkillMustafa Ozhan
02/21/2023, 8:29 AMfun CoroutineScope.launchIgnored(function: suspend () -> Unit) {
launch {
function()
}
}
then i use as
fun load() = scope.launchIgnored {
...
}Sam
02/21/2023, 8:55 AMload to return Unit instead of a Job? In most places I can think of, it doesn’t matter. I would just return a Job and ignore it at the call-site. The main exception I can think of is if it’s an override and you don’t control the return type.Mustafa Ozhan
02/21/2023, 8:58 AMUnit but because launch returns Jobs it gives errorsdarkmoon_uk
02/21/2023, 9:07 AMmcpiroman
02/21/2023, 11:08 AMfun load(): Unit = scope.launch {
...
}Sam
02/21/2023, 11:09 AMSam
02/21/2023, 11:09 AMribesg
02/21/2023, 12:59 PMfun load() {
scope.launch {
task()
}
}
suspend fun task() {
…
}
You could even have some error management in load() instead of in task() so that task() is easier to read