kotlin-interactive-shell
kotlin-interactive-shell copied to clipboard
Make first class support for coroutines
I am considering kotlin and coroutines as an inseparable couple. Would be nice to have a super-easy way to test them. For the best experience, I am missing few features:
- [ ] Easy way to include coroutines package instead of
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
. For example:coroutines
or:c
. Or support parameters, likeki --coroutines
. I don't mind if coroutines will be included by default. - [ ] Suspend function mode. Currently I am needed to write
runBlocking { flowOf(42).first() }
. But would be nice to be able write something like that:
[20] flowOf(42)
res17: kotlinx.coroutines.flow.Flow<Int> = kotlinx.coroutines.flow.FlowKt__BuildersKt$flowOf$$inlined$unsafeFlow$2@5863ef93
[21] res17.first() //does not work for now
res18: String = 42
This could work as a special mode enabled with :coroutines
along with imported packages or could be another command like :suspend
or :s
which toggles suspend mode on/off.
- [ ] Do not expose implementation details like
FlowKt__BuildersKt$flowOf$$inlined$unsafeFlow$2@5863ef93
- [ ] I am not sure if it is possible, but would be nice to cancel the suspended coroutine with some shortcut. For example with
ctrl-C
. It could be very useful if a never-ending coroutine was launched by accident.
Thank you!
I need to do some research here, but I'll back.
Maybe it could be an even wider feature request, not only a special mode for ki, but also a special mode for any other Kotlin script, I also interested in this feature and in the context of .kts files too. Should I create a feature request on kotlin issue tracker?
Any updates on this?