Skip to content

types.jl: sleep with Date.Period types #19749

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

Merged
merged 1 commit into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions base/dates/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,8 @@ Base.isless(x::Date,y::Date) = isless(value(x),value(y))
Base.isless(x::DateTime,y::DateTime) = isless(value(x),value(y))
Base.isless(x::TimeType,y::TimeType) = isless(promote(x,y)...)
==(x::TimeType,y::TimeType) = ===(promote(x,y)...)

import Base: sleep,Timer,timedwait
sleep(time::Period) = sleep(toms(time) / 1000)
Timer(time::Period, repeat::Period=Second(0)) = Timer(toms(time) / 1000,toms(repeat) / 1000)
timedwait(testcb::Function, time::Period) = timedwait(testcb, toms(time) / 1000)
2 changes: 1 addition & 1 deletion test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ end
@async begin sleep(2.0); put!(rr3, :ok) end

tic()
timedwait(callback, 1.0)
timedwait(callback, Dates.Second(1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary, shouldn't timedwait(callback, 1.0) still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As TotalVerb said, The Period version dispatches to the Real version anyway.

et=toq()
# assuming that 0.5 seconds is a good enough buffer on a typical modern CPU
try
Expand Down
61 changes: 31 additions & 30 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,37 +347,38 @@ for T in (Int32, Int64, Float32, Float64)
@test varmax[] === T(maximum(1:nloops))
@test varmin[] === T(0)
end

let async = Base.AsyncCondition(), t
c = Condition()
task = schedule(Task(function()
notify(c)
wait(c)
t = Timer(0.06)
wait(t)
ccall(:uv_async_send, Void, (Ptr{Void},), async)
ccall(:uv_async_send, Void, (Ptr{Void},), async)
for period in (0.06, Dates.Millisecond(60))
let async = Base.AsyncCondition(), t
c = Condition()
task = schedule(Task(function()
notify(c)
wait(c)
t = Timer(period)
wait(t)
ccall(:uv_async_send, Void, (Ptr{Void},), async)
ccall(:uv_async_send, Void, (Ptr{Void},), async)
wait(c)
sleep(period)
ccall(:uv_async_send, Void, (Ptr{Void},), async)
ccall(:uv_async_send, Void, (Ptr{Void},), async)
end))
wait(c)
sleep(0.06)
ccall(:uv_async_send, Void, (Ptr{Void},), async)
ccall(:uv_async_send, Void, (Ptr{Void},), async)
end))
wait(c)
notify(c)
delay1 = @elapsed wait(async)
notify(c)
delay2 = @elapsed wait(async)
@test istaskdone(task)
@test delay1 > 0.05
@test delay2 > 0.05
@test isopen(async)
@test !isopen(t)
close(t)
close(async)
@test_throws EOFError wait(async)
@test !isopen(async)
@test_throws EOFError wait(t)
@test_throws EOFError wait(async)
notify(c)
delay1 = @elapsed wait(async)
notify(c)
delay2 = @elapsed wait(async)
@test istaskdone(task)
@test delay1 > 0.05
@test delay2 > 0.05
@test isopen(async)
@test !isopen(t)
close(t)
close(async)
@test_throws EOFError wait(async)
@test !isopen(async)
@test_throws EOFError wait(t)
@test_throws EOFError wait(async)
end
end

# Compare the two ways of checking if threading is enabled.
Expand Down