See ‘producer’ section here: <https://medium.com/@...
# kotlin-native
k
m
Great article, thanks! But still I have a question about Kotlin Native invariant. It's that the object is either owned by a single worker. Can I create the object in a worker then detach it and transfer to other a worker? I have seen your tests on GitHub: https://github.com/touchlab/StrangerThreadsSample/blob/master/src/nativeTest/kotlin/sample/DetachedObjectGraphTests.kt Why need
DetachedObjectGraph
in
detach()
test?
SomeData
has't any owners now then. Makes sense? Are there some example manually
detach
and
attach
in more real usecases?
k
" It’s that the object is either owned by a single worker.” To be precise, mutable (non-frozen) state can be visible to only one thread. A worker runs operations in its own thread, but you’re not always inside a “worker”.
“Can I create the object in a worker then detach it and transfer to other a worker?” Yes, but the same rules apply. You need to pass it to the other worker’s producer without that reference still being available in the caller. An example of what you’re thinking would help. I can point out what won’t work
“Why need
DetachedObjectGraph
in
detach()
test?
SomeData
has’t any owners now then. Makes sense?” I don’t really understand what you’re asking.
“Are there some example manually
detach
and
attach
in more real usecases?” I don’t have many. I don’t use detach much (I point that out in the article)