Skip to content

Commit ea73c84

Browse files
Merge pull request #19749 from Shade5/dug
types.jl: sleep with Date.Period types
2 parents 0f2b22b + 4be146b commit ea73c84

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

base/dates/types.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,8 @@ Base.isless(x::Date,y::Date) = isless(value(x),value(y))
241241
Base.isless(x::DateTime,y::DateTime) = isless(value(x),value(y))
242242
Base.isless(x::TimeType,y::TimeType) = isless(promote(x,y)...)
243243
==(x::TimeType,y::TimeType) = ===(promote(x,y)...)
244+
245+
import Base: sleep,Timer,timedwait
246+
sleep(time::Period) = sleep(toms(time) / 1000)
247+
Timer(time::Period, repeat::Period=Second(0)) = Timer(toms(time) / 1000,toms(repeat) / 1000)
248+
timedwait(testcb::Function, time::Period) = timedwait(testcb, toms(time) / 1000)

test/channels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ end
9292
@async begin sleep(2.0); put!(rr3, :ok) end
9393

9494
tic()
95-
timedwait(callback, 1.0)
95+
timedwait(callback, Dates.Second(1))
9696
et=toq()
9797
# assuming that 0.5 seconds is a good enough buffer on a typical modern CPU
9898
try

test/threads.jl

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -347,37 +347,38 @@ for T in (Int32, Int64, Float32, Float64)
347347
@test varmax[] === T(maximum(1:nloops))
348348
@test varmin[] === T(0)
349349
end
350-
351-
let async = Base.AsyncCondition(), t
352-
c = Condition()
353-
task = schedule(Task(function()
354-
notify(c)
355-
wait(c)
356-
t = Timer(0.06)
357-
wait(t)
358-
ccall(:uv_async_send, Void, (Ptr{Void},), async)
359-
ccall(:uv_async_send, Void, (Ptr{Void},), async)
350+
for period in (0.06, Dates.Millisecond(60))
351+
let async = Base.AsyncCondition(), t
352+
c = Condition()
353+
task = schedule(Task(function()
354+
notify(c)
355+
wait(c)
356+
t = Timer(period)
357+
wait(t)
358+
ccall(:uv_async_send, Void, (Ptr{Void},), async)
359+
ccall(:uv_async_send, Void, (Ptr{Void},), async)
360+
wait(c)
361+
sleep(period)
362+
ccall(:uv_async_send, Void, (Ptr{Void},), async)
363+
ccall(:uv_async_send, Void, (Ptr{Void},), async)
364+
end))
360365
wait(c)
361-
sleep(0.06)
362-
ccall(:uv_async_send, Void, (Ptr{Void},), async)
363-
ccall(:uv_async_send, Void, (Ptr{Void},), async)
364-
end))
365-
wait(c)
366-
notify(c)
367-
delay1 = @elapsed wait(async)
368-
notify(c)
369-
delay2 = @elapsed wait(async)
370-
@test istaskdone(task)
371-
@test delay1 > 0.05
372-
@test delay2 > 0.05
373-
@test isopen(async)
374-
@test !isopen(t)
375-
close(t)
376-
close(async)
377-
@test_throws EOFError wait(async)
378-
@test !isopen(async)
379-
@test_throws EOFError wait(t)
380-
@test_throws EOFError wait(async)
366+
notify(c)
367+
delay1 = @elapsed wait(async)
368+
notify(c)
369+
delay2 = @elapsed wait(async)
370+
@test istaskdone(task)
371+
@test delay1 > 0.05
372+
@test delay2 > 0.05
373+
@test isopen(async)
374+
@test !isopen(t)
375+
close(t)
376+
close(async)
377+
@test_throws EOFError wait(async)
378+
@test !isopen(async)
379+
@test_throws EOFError wait(t)
380+
@test_throws EOFError wait(async)
381+
end
381382
end
382383

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

0 commit comments

Comments
 (0)