class EventCore::Source
Low level event source representation. Only needed when the convenience APIs on EventLoop are not enough.
Public Class Methods
# File lib/event_core.rb, line 18 def initialize @closed = false @ready = false @timeout_secs = nil @trigger = nil end
Public Instance Methods
Close this source, marking it for removal from the main loop.
# File lib/event_core.rb, line 74 def close! @closed = true @trigger = nil # Help the GC, if the closure holds onto some data end
Check to see if close!() has been called.
# File lib/event_core.rb, line 69 def closed? @closed end
Consume pending event data and set readiness to false
# File lib/event_core.rb, line 55 def consume_event_data! raise "Source not ready: #{self}" unless ready? data = @event_data @event_data = nil @ready = false data end
Raw event data is passed to this function before passed to the trigger
# File lib/event_core.rb, line 64 def event_factory(event_data) event_data end
Consume pending event data and fire the trigger, closing if the trigger returns (explicitly) false.
# File lib/event_core.rb, line 86 def notify_trigger event_data = consume_event_data! event = event_factory(event_data) if @trigger # Not just !@trigger.call(event), we want explicitly "false" close! if @trigger.call(event) == false end end
Mark source as ready
# File lib/event_core.rb, line 33 def ready!(event_data=nil) @ready = true @event_data = event_data end
Check if a source is ready. Called on each main loop iteration. May have side effects, but should not leave ready state until consume_event_data!() has been called.
# File lib/event_core.rb, line 28 def ready? @ready end
An optional IO object to select on
# File lib/event_core.rb, line 44 def select_io nil end
Returns :read, :write, or nil. If select_io
is non-nil, then the select_type
must not be nil.
# File lib/event_core.rb, line 50 def select_type nil end
Timeout in seconds, or nil
# File lib/event_core.rb, line 39 def timeout @timeout_secs end
Set the trigger function to call on events to the given block
# File lib/event_core.rb, line 80 def trigger(&block) @trigger = block end