https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

Javier

03/05/2020, 10:16 PM
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

streetsofboston

03/05/2020, 10:21 PM
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

Javier

03/05/2020, 10:23 PM
Yeah, I know I can do that, but I would like to use the reference
s

streetsofboston

03/05/2020, 10:23 PM
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

Javier

03/05/2020, 10:24 PM
Yeah, at this moment maybe is not possible directly
message has been deleted
message has been deleted
Maybe it can help someone
s

streetsofboston

03/05/2020, 10:58 PM
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

octylFractal

03/05/2020, 11:15 PM
👍 2
s

streetsofboston

03/05/2020, 11:27 PM
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

Javier

03/06/2020, 8:56 AM
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

elizarov

03/06/2020, 10:07 AM
Might come in 1.4. Not definite yet.
👍 1
4 Views