obobo
11/05/2020, 10:26 PMForkConnected
to start up fibers the correct abstraction?
I use Channels to have different Jobs communicate. Are queues used for a similar purpose as channels? Is there an equivalent to select
? In particular, I'd like have some behavior repeated periodically OR when a signal is received, whichever is first. Would I use a Race
with a Schedule
for that?simon.vergauwen
11/06/2020, 8:28 AMForkConnected
is indeed used to start lonng-running workers or Fibers which run independent from the main logic, but have their cancellation wired together. You can also use ForkAndForget
if you want to disregard cancellation for you long-running task or ForkScoped
if you want to couple it's cancellation to somethin arbitrary else.
You can communicate between long-working tasks in different ways, we have serveral data types like Promise
or ConcurrentVar
. We also have Queue
but that's in the streaming package which will be moved to a seperate module soon. It covers most of the behavior of Channel
IIRC. Depending on the use-case.
The equivalent of select
would be race
indeed. You could do something like.
val cancelSignal = Promise<Unit>() //complete when you want to cancel behavior
raceN({ repeat(schedule) { behavior() } }, { cancelSignal.get() })