PeaceFounder.Schedulers

PeaceFounder.Schedulers.SchedulerType
mutable struct Scheduler
    condition::Condition
    pool_interval::Union{Int, Nothing}
    retry_interval::Union{Int, Nothing}
    delay::Int
    started::Bool
    finished::Bool
    schedule::Vector{Tuple{DateTime, <:Any}}
end

Represents a waitable object which resumes at predetermined scheduled times. A typical use for it is in the event loop like:

scheduler = Scheduler(; retry_interval = 1)

lock(scheduler) do 
    schedule!(scheduler, now() + Second(1), value)
end

while true
    value = wait(scheduler)
    try
        # Do some stuff
    catch
        retry!(scheduler)
    end
end

In the event loop one manages a state machine which can succed and fail. If it succeds a scheduled time is taken out from the scheduler and proceeds waiting the next event. In the case event at scheduled time had failed the scheduler is notified with retry! method and attempts to run the event loop againafter retry_interval until succeeds.

source
Base.lockMethod
lock(scheduler::Scheduler)

Lock a scheduler. This is necessary to avoid simultanous modifications of the schedule field. Note that other Scheduler fields are not protected with the lock as thoose are considered internal.

source
Base.notifyMethod
notify(scheduler::Scheduler[, value])

Notify a scheduler with a value which is returned at wait.

source
Base.waitMethod
wait(scheduler::Scheduler)

Wait until next event is reached and return it's value. In the case event have run through smoothelly the scheduler event is droped with the next wait call. See also retry! method.

source
PeaceFounder.Schedulers.schedule!Method
schedule!(scheduler::Scheduler, timestamp::DateTime[, value])

Schedule an event at timestamp with a provided value. To avoid messing up a schedule acquire a scheduler's lock before adding the event as:

lock(scheduler) do
    schedule!(scheduler, now() + Second(1), value)
end
source