simon.vergauwen
08/06/2020, 10:09 AMForkConnected { // <-- Launches new fiber on `suspsend` context and cancels when `suspend` was cancelled.
sleep(20_000.milliseconds)
getLastLocation() // <-- suspend
}
simon.vergauwen
08/06/2020, 10:10 AMForkConnected
is used to launch it in a seperate Fiber
, so the code continues immediately similarly to a call to schedule
.simon.vergauwen
08/06/2020, 10:10 AMcarbaj0
08/06/2020, 10:13 AMcarbaj0
08/06/2020, 10:13 AMsimon.vergauwen
08/06/2020, 10:14 AM0.11.0-SNAPSHOT
.
You can do something similar with IO
albeit a bit more cumbersome since we currently don't expose ForkConnected
there.simon.vergauwen
08/06/2020, 10:15 AMval getlastLocationAfterDelay = IO.sleep(20_000.milliseconds)
.followedBy(getLastLocationIO())
.fork()
Jannis
08/06/2020, 10:16 AMSchedule
datatype then, or simply run the loop yourselfsimon.vergauwen
08/06/2020, 10:17 AMTimer
runs a Schedule
not just delay a task 🤦♂️
My bad, I was thinking about schedule
from ScheduledExecutorService
simon.vergauwen
08/06/2020, 10:19 AMval 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 🙂simon.vergauwen
08/06/2020, 10:20 AMcarbaj0
08/06/2020, 10:22 AM