Hello, I have an application written using kotlinx...
# arrow
o
Hello, I have an application written using kotlinx coroutines, and as a proof of concept/learning opportunity I'm thinking of porting it to arrow-fx, but I'd like to confirm that I've got some concepts straight, I wasn't able to find answers in the docs, so apologies if this is already covered somewhere. I use launch to start up long-running 'worker' Jobs, which I sometimes need to cancel and restart. Is using
ForkConnected
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?
s
Hey Alan,
ForkConnected
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.
Copy code
val cancelSignal = Promise<Unit>() //complete when you want to cancel behavior

raceN({ repeat(schedule) { behavior() } }, { cancelSignal.get() })
👍 1