Hi guys, i have a question about coroutine seriali...
# announcements
d
Hi guys, i have a question about coroutine serialization. Is it already implemented or not? i can't find any example. I just find this discussion https://github.com/Kotlin/kotlin-coroutines/issues/28, but last comment was more than six months ago.
e
dmitriy.govorukhin: Please, join #coroutines for discussion. In short coroutine stat is serialization, but the devil is in details (like context and other references that coroutine may hold unto). What is your use-case?
d
Thanks for quick answer, my case is, a want use corounite in distributed compute. Run coroutine on some node, after some useful work, suspend and serialize coroutine scope, next send to another node, and resume... etc. Can you give me any idea how i can do this?
e
There's a lot of things to figure out. First of all, you'll have to use some custom serialization, that can "cut-out" whatever context your computation was using on one machine and carefully install the corresponding context on the other.
I would suggest to solve this problem without coroutines first (e.g. use regular callback for async computations instead of coroutines) and then, when it works, transplant your solution to coroutines
d
Thanks, it's understandable, but I have a misunderstanding of how to continue the coroutine from the place where it was suspended after restoring the context on another node. Have you any example resume coroutine after restore context?
e
All the coroutine state is stored in its continuation object. All you need to do is to serialize and transfer continuation to the other machine and then invoke
resume
d
Okay, got it, will try to do. Many thanks.
e
Continuation is just like callback. If you can serialize and transfer computation that is waiting on a callback, then your solution will work with coroutines just as well.
d
Yes, i know it, but for me it was not clear how to resume coroutine after restore, I thought it needed some extra steps.
j
In the real world we use queues for this
not a use case for serialization