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

ghedeon

11/11/2019, 4:17 PM
Trying to invoke a coroutine from Java, for some legacy code. This doesn't start it so far, do I miss something?
Copy code
CoroutineScope scope = ViewModelKt.getViewModelScope(this);
        BuildersKt.launch(scope, scope.getCoroutineContext(), CoroutineStart.DEFAULT,
                (_scope, continuation) -> signUp.invoke(params, continuation)
        );
z

Zach Klippenstein (he/him) [MOD]

11/11/2019, 8:00 PM
The simplest way to do that is just write yourself a helper function in kotlin to provide a java-friendly API. But if that's not possible, I think your problem might be that you need to return
COROUTINE_SUSPENDED
from your lambda to indicate that the function didn't finish. But I think you also then need to check the return value of your signup function to either return directly or return that constant. It would be much better to just write a helper in kotlin.
🙏 1
1
g

ghedeon

11/12/2019, 6:53 AM
I see, that was my backup plan, yes. Interesting details, thank you! 👍
3 Views