@@ -90,8 +90,8 @@ mutable struct Timer
90
90
cond:: ThreadSynchronizer
91
91
@atomic isopen:: Bool
92
92
@atomic set:: Bool
93
- timeout :: Real
94
- interval :: Real
93
+ timeout_ms :: UInt64
94
+ interval_ms :: UInt64
95
95
96
96
function Timer (timeout:: Real ; interval:: Real = 0.0 )
97
97
timeout ≥ 0 || throw (ArgumentError (" timer cannot have negative timeout of $timeout seconds" ))
@@ -101,7 +101,7 @@ mutable struct Timer
101
101
intervalms = ceil (UInt64, interval * 1000 )
102
102
loop = eventloop ()
103
103
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 )
105
105
associate_julia_struct (this. handle, this)
106
106
iolock_begin ()
107
107
err = ccall (:uv_timer_init , Cint, (Ptr{Cvoid}, Ptr{Cvoid}), loop, this)
@@ -116,10 +116,26 @@ mutable struct Timer
116
116
return this
117
117
end
118
118
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 )
119
133
120
134
function show (io:: IO , t:: Timer )
121
135
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 )) " )
123
139
end
124
140
125
141
unsafe_convert (:: Type{Ptr{Cvoid}} , t:: Timer ) = t. handle
0 commit comments