Skip to content

Commit ea6f9d0

Browse files
suggestions
Co-Authored-By: Jeff Bezanson <jeff.bezanson@gmail.com>
1 parent 72e94b1 commit ea6f9d0

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

base/asyncevent.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ mutable struct Timer
9090
cond::ThreadSynchronizer
9191
@atomic isopen::Bool
9292
@atomic set::Bool
93-
timeout::Real
94-
interval::Real
93+
timeout_ms::UInt64
94+
interval_ms::UInt64
9595

9696
function Timer(timeout::Real; interval::Real = 0.0)
9797
timeout 0 || throw(ArgumentError("timer cannot have negative timeout of $timeout seconds"))
@@ -101,7 +101,7 @@ mutable struct Timer
101101
intervalms = ceil(UInt64, interval * 1000)
102102
loop = eventloop()
103103

104-
this = new(Libc.malloc(_sizeof_uv_timer), ThreadSynchronizer(), true, false, timeout, interval)
104+
this = new(Libc.malloc(_sizeof_uv_timer), ThreadSynchronizer(), true, false, timeoutms, intervalms)
105105
associate_julia_struct(this.handle, this)
106106
iolock_begin()
107107
err = ccall(:uv_timer_init, Cint, (Ptr{Cvoid}, Ptr{Cvoid}), loop, this)
@@ -116,10 +116,26 @@ mutable struct Timer
116116
return this
117117
end
118118
end
119+
function getproperty(t::Timer, f::Symbol)
120+
if f == :timeout
121+
if t.timeout_ms == 0
122+
return t.timeout_ms / 1000
123+
else # undo the +1ms from the constructor
124+
return (t.timeout_ms - 1) / 1000
125+
end
126+
elseif f == :interval
127+
return t.interval_ms / 1000
128+
else
129+
return getfield(t, f)
130+
end
131+
end
132+
propertynames(::Type{Timer}) = (:handle, :cond, :isopen, :set, :timeout_ms, :timeout, :interval_ms, :interval)
119133

120134
function show(io::IO, t::Timer)
121135
state = isopen(t) ? "open" : "closed"
122-
print(io, "Timer ($state, timeout: $(t.timeout), interval: $(t.interval)) @0x$(string(convert(UInt, pointer_from_objref(t)), base = 16, pad = Sys.WORD_SIZE>>2))")
136+
interval = t.interval
137+
interval_str = interval > 0 ? ", interval: $(t.interval) s" : ""
138+
print(io, "Timer ($state, timeout: $(t.timeout) s$interval_str) @0x$(string(convert(UInt, pointer_from_objref(t)), base = 16, pad = Sys.WORD_SIZE>>2))")
123139
end
124140

125141
unsafe_convert(::Type{Ptr{Cvoid}}, t::Timer) = t.handle

0 commit comments

Comments
 (0)