:wave: hi, is it possible to suspend a suspend fun...
# announcements
👋 hi, is it possible to suspend a suspend function then continue/resume it more than once?
Can you give us a use case? The simple answer is probably 'yes' - for example, try putting
into your suspending method more than once - that will result in it being suspended multiple times.
Sorry, I believe I meant coroutine. Say I have a suspend function that prints a string once. Is it possible to make a coroutine context that would print it twice, given a single application?
Seems possible e.g. by making a custom dispatcher that dispatched twice; but it sounds like it could get hacky and 'abusive' - why not just call your suspend function twice?
I’m curious about effect handling. Wondering if kotlin can accommodate it.
it seems totally unsafe to allow it, and I'm pretty sure it won't work anyway: https://github.com/JetBrains/kotlin/blob/0c13a7f89a166015fcc281da745a5fc0719f73c4/libraries/stdlib/jvm/src/kotlin/coroutines/SafeContinuationJvm.kt#L45
Copy code
else -> throw IllegalStateException("Already resumed")
You may want to look into
that has the same structured concurrency as suspend funs but can emit more than one value.
What's the scene you faced? Looks it's a big abused usecase.
If you only want a try. Maybe you need to modify the internal state of the state machines. 😋