Philip Dukhov
11/01/2021, 12:36 PMsuspend fun some(argument: Int) : Unit {
// process
}
fun service(some: (Int) -> Unit) {
some(1)
}
And I'd like to pass some
by reference like this:
val coroutineScope = ...
service(::some::launchIn(coroutineScope))
The function launchIn(coroutineScope)
is what I'm looking for, am I missing something built in, or is there a way I can create it?Joffrey
11/01/2021, 2:33 PMservice { arg ->
coroutineScope.launch {
some(arg)
}
}
Joffrey
11/01/2021, 2:36 PMservice
here) relies on the function being called in place, but here you are launching it asynchronouslyPhilip Dukhov
11/01/2021, 2:40 PMservice
shouldn't decide on which scope to run this function.
When I have many of arguments like this, the code looks like a mess. All I really need to see when reading this code is which function will be called and on which scope. Having 5 lines instead of 1 doesn't looks nice. This's what my launchIn
is trying to solve.Joffrey
11/01/2021, 3:01 PM