Class: EventCore::TimeoutSource
Overview
A source that fires the trigger depending on a timeout.
Instance Method Summary collapse
-
#initialize(secs) ⇒ TimeoutSource
constructor
A new instance of TimeoutSource.
- #ready? ⇒ Boolean
- #timeout ⇒ Object
Methods inherited from Source
#close!, #closed?, #consume_event_data!, #event_factory, #notify_trigger, #ready!, #select_io, #select_type, #trigger
Constructor Details
#initialize(secs) ⇒ TimeoutSource
Returns a new instance of TimeoutSource.
314 315 316 317 318 |
# File 'lib/event_core.rb', line 314 def initialize(secs) super() @timeout_secs = secs @next_timestamp = Time.now.to_f + secs end |
Instance Method Details
#ready? ⇒ Boolean
320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/event_core.rb', line 320 def ready? return true if @ready now = Time.now.to_f if now >= @next_timestamp ready! @next_timestamp = now + @timeout_secs return true end false end |
#timeout ⇒ Object
332 333 334 335 |
# File 'lib/event_core.rb', line 332 def timeout delta = @next_timestamp - Time.now.to_f delta > 0 ? delta : 0 end |