Question about Workers on Kotlin/Native \ MP on windows:
(I figured the coroutines channel was still the best place to ask the following, even tho I can't do this with coroutines (yet?).)
I've checked out the workers example here [ https://github.com/JetBrains/kotlin-native/blob/master/samples/workers/src/workersMain/kotlin/Workers.kt ] and got that to work,
but I am now wondering if there is a way ( in Kotlin, without resorting to sharing a buffer via C or something like that ) to have a long running process ( e.g. another windows program launched via popen ) running in a worker which periodically sends data ( e.g. a string of the output of the program ) back to the main thread. From what I understand, workers allow you to do work
in a separate "environment", and then "transfer back" the (immutable) data once the worker is done. Is there a canonical way to periodically "send data back" to the "main thread"?
12/06/2019, 6:29 PM
Workers are not related to coroutines directly.
Essentially what you looking for is possible with multithreaded coroutines and Flow, it's the best high level primitive for such task, but it's still in development
12/06/2019, 6:32 PM
can I do it with just workers at this point?
12/06/2019, 6:51 PM
You probably can write some abstraction that runs workers periodically to check state or just launch permanently running worker that does what you need and somehow share state using atomic or some similar approach
Worker is just an abstraction to launch some code in background thread, nothing more
12/06/2019, 9:27 PM
can you elaborate what you mean with "using atomic"? Apologies, I'm from the land of virtual machines, have not worked with C in a really long time, and never much.
12/07/2019, 5:46 AM
It's not something C related, it's K/N primitive
12/10/2019, 6:35 PM
I see. Any hints how to "wait" for a AtomicInt lock on the main thread? with the coroutine mutex? Or a posix function?
12/11/2019, 1:17 AM
You cannot wait, but using coroutines you can poll on it without blocking