:wave: hi, is it possible to suspend a suspend fun...
# announcements
f
👋 hi, is it possible to suspend a suspend function then continue/resume it more than once?
d
Can you give us a use case? The simple answer is probably 'yes' - for example, try putting
delay(<someDuration>)
into your suspending method more than once - that will result in it being suspended multiple times.
f
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?
d
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?
f
I’m curious about effect handling. Wondering if kotlin can accommodate it.
e
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")
s
You may want to look into
Flow
that has the same structured concurrency as suspend funs but can emit more than one value.
i
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. 😋