https://kotlinlang.org logo
#announcements
Title
# announcements
d

dmitriy.govorukhin

04/28/2017, 2:23 PM
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

elizarov

04/28/2017, 2:36 PM
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

dmitriy.govorukhin

04/28/2017, 2:44 PM
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

elizarov

04/28/2017, 2:57 PM
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

dmitriy.govorukhin

04/28/2017, 3:01 PM
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

elizarov

04/28/2017, 3:05 PM
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

dmitriy.govorukhin

04/28/2017, 3:06 PM
Okay, got it, will try to do. Many thanks.
e

elizarov

04/28/2017, 3:07 PM
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

dmitriy.govorukhin

04/28/2017, 3:10 PM
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

johnl

04/29/2017, 12:59 PM
In the real world we use queues for this
not a use case for serialization
55 Views