263: def initialize (options={}, &handler)
264: @running = false
265: @start_time = nil
266:
267: if options.kind_of? Numeric
268: options = { :interval => options }
269: end
270:
271: if options[:interval]
272: @interval = options[:interval].to_f
273: else
274: @interval = DEFAULT_INTERVAL
275: end
276:
277: if options[:tolerance]
278: @tolerance = options[:tolerance].to_f
279: elsif DEFAULT_TOLERANCE < @interval
280: @tolerance = DEFAULT_TOLERANCE
281: else
282: @tolerance = 0.0
283: end
284:
285: @event_loop = options[:event_loop] || EventLoop.current
286:
287: if block_given?
288: add_signal_handler(:alarm, &handler)
289: start unless options[:start?] == false
290: else
291: start if options[:start?]
292: end
293: end