When using Arrow Fx Coroutines ```ForkConnected {...
# arrow
s
When using Arrow Fx Coroutines
Copy code
ForkConnected { // <-- Launches new fiber on `suspsend` context and cancels when `suspend` was cancelled.
  sleep(20_000.milliseconds)
  getLastLocation() // <-- suspend
}
ForkConnected
is used to launch it in a seperate
Fiber
, so the code continues immediately similarly to a call to
schedule
.
And besides that we can just simply wait ourselves, and run any arbitrary code afterwards.
c
ok, I am using the arrow version = "0.10.5"
do i need to upgrade it?
s
Ah sorry, this snippet is using Arrow Fx Coroutines
0.11.0-SNAPSHOT
. You can do something similar with
IO
albeit a bit more cumbersome since we currently don't expose
ForkConnected
there.
Copy code
val getlastLocationAfterDelay = IO.sleep(20_000.milliseconds)
    .followedBy(getLastLocationIO())
    .fork()
j
Also this is repeating right? You may want to look at our
Schedule
datatype then, or simply run the loop yourself
s
Oh... doi. A
Timer
runs a
Schedule
not just delay a task 🤦‍♂️ My bad, I was thinking about
schedule
from
ScheduledExecutorService
Copy code
val spaced = Schedule.forMonad(IO.monad()) {
  spaced(20_000.milliseconds)
}

val getLastLocation: IO<Unit> = ...

val onSchedule = getLastLocation.repeat(spaced)
This however is pseudo code. It defines a schedule that will run every 20_000 milliseconds, and then you can apply it on a
IO
task using
repeat
(there is also a
retry
operation that follows the schedule whenever an error occurs). @Jannis wrote very nice docs for this data type 🙂
c
yes, I will review the documentation, which is very well written jeje
👍 1