Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix schedule_unique and unschedule #54

Merged
merged 1 commit into from
Dec 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/timer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const scheduler = Ref{Scheduler}()
elapsed(s::Scheduler) = elapsed(s.timer)
Base.push!(s::Scheduler, x::Scheduled) = push!(s.actions, x)
Base.filter!(x::Scheduled, s::Scheduler) = filter!(a->x!=a, s.actions)
Base.filter!(x::WeakRef, s::Scheduler) = filter!(a->x!=a.action, s.actions)
clear!(s::Scheduler) = deleteat!(s.actions, 1:length(s.actions))

"""
Expand Down Expand Up @@ -156,7 +157,7 @@ end
Takes a function and an interval in seconds, and sets the function to run after that interval only if the same function handle was not previously set.
"""
function schedule_unique(f::Function, interval)
filter(WeakRef(f), scheduler)
filter!(WeakRef(f), scheduler[])
push!(scheduler[], OnceScheduled(WeakRef(f), elapsed(scheduler[])+interval*1e9) )
@debug "Added Unique Schedule" f
end
Expand Down