The coroutines keep states: > However, multi-sh...
# coroutines
y
The coroutines keep states:
However, multi-shot continuations can be implemented as a separate library by suspending coroutine with low-level coroutine intrinsics and cloning the state of the coroutine that is captured in continuation, so that its clone can be resumed again.
Is that actually possible? My understanding is that nasty reflection tricks are needed (which make the code not multiplatform compatible either). Is there an example of this out there? If it needs reflection tricks and all that, could a
CopyableContinuation
interface be provided that allows such a thing?
I found this, but it uses reflection. Is there a way that doesn't?
s
This question reminds me of https://github.com/Kotlin/kotlinx.coroutines/issues/76. That thread is about serialisation, not cloning, but it seems like the same basic principle. The original idea in this case, which is also very briefly mentioned in the KEEP, was that a suspended coroutine could be persisted in a DB or sent to another machine. But as far as I could tell, all the attempted solutions in the thread are outdated and there's no longer a way to make it work.
y
That does seem very similar yes. I guess the difference is that non-serializable values can be supported when cloning, so technically cloning is easier than serialising (e.g. you have an input stream, one can clone a continuation while referencing the same input stream).
👍 1