I think I got a lint issue when I use a suspend fu...
# coroutines
j
I think I got a lint issue when I use a suspend function as parameter
message has been deleted
message has been deleted
The last image solves the problem, obviously the suspend is not needed there, but if I want to use the function directly how you can see in the first image, I need the suspend, is there a workarround to avoid this?
s
Yeah… any
fun () -> T
is not the same as
fun suspend() -> T
nor vice versa….. Instead of the unused
suspend
of your
populateTextView
, do this instead:
Copy code
lifecycleScope.launch {
  viewModel.users.collect {
    populateTextView(it)
  }
}
j
Yeah, I know I can do that, but I would like to use the reference
s
It would be great if any
fun A.(B) -> C
would be assignable to a
suspend fun A.(B) -> C
…. but that is not the case…..
Thing is a
suspend fun A.(B) -> C
translates to a
fun A.(B, Continuation<C>) -> Any
…. and that is not compatible with `fun A.(B) -> C`…. But it could be solved with some syntactic sugar 😄
j
Yeah, at this moment maybe is not possible directly
message has been deleted
message has been deleted
Maybe it can help someone
s
I guess the compiler can’t deal with an overloaded definition of
collect
where the diff of its parameter is only a missing
suspend
keyword? What happens if you’d rename
populate
to
collect
?
o
👍 2
s
And Roman’s answer to that issue is “The design resolution is that conversion from regular functions to suspending function will be supported.” I guess it’s in the pipeline, just not yet implemented 🤞
j
Yeah, I can't use collect
The problem of that answer is... 2017 But I think it is planned for 1.4. Maybe @elizarov can confirm
e
Might come in 1.4. Not definite yet.
👍 1