Hello colleagues,
i tried a few things, the closest to a solution is a low-level call to
libuv:
# timer restart demo
type t_status
i::Int64
end
function t1(u::Timer)
# finishing timer -> just close and display
close(u);
display("t1, finished")
display(Dates.unix2datetime(time()));
end
function t2(u_own::Timer,ts::t_status,u_other)
# restarting timer -> track status and restart u_other
ts.i += 1
display(Dates.unix2datetime(time()));
display(ts.i);
if ts.i > 9
close(u_own)
else
ccall(:uv_timer_again,Void, (Ptr{Void},), u_other.handle)
end
end
display("get u1/t1 running -> would return in 2.0s")
display(Dates.unix2datetime(time()));
u1 = Timer(u1 -> t1(u1),2.0,2.0);
display("get u2/t2 running -> update 10 times")
ts = t_status(0);
u2 = Timer(u2 -> t2(u2,ts,u1),0.5,0.5);
running this:
julia> include("timer-restart-demo.jl")
"get u1/t1 running -> would return in 2.0s"
2016-01-02T15:15:51.466
"get u2/t2 running -> update 10 times"
Timer(Ptr{Void} @0x0000000002990420,Condition(Any[2016-01-02T15:15:52.162]
),1true
)
julia> 2016-01-02T15:15:52.656
2
2016-01-02T15:15:53.157
3
2016-01-02T15:15:53.658
4
2016-01-02T15:15:54.159
5
2016-01-02T15:15:54.659
6
2016-01-02T15:15:55.159
7
2016-01-02T15:15:55.66
8
2016-01-02T15:15:56.161
9
2016-01-02T15:15:56.661
10
"t1, finished"
2016-01-02T15:15:58.169
julia>
So, the original u1/t1 is only executed after the 10 restart by u2/t2.
I can live with the ccall, but would it make sense to contribute this to
the overall Base.Timer?
Wishing a happy day,
Andreas