Class: EmPipelines::IOEventSource

Inherits:
EventSource show all
Defined in:
lib/empipelines/io_event_source.rb

Instance Method Summary collapse

Methods inherited from EventSource

#on_event, #on_finished

Constructor Details

#initialize(em, file_path) ⇒ IOEventSource

Returns a new instance of IOEventSource.



6
7
8
9
# File 'lib/empipelines/io_event_source.rb', line 6

def initialize(em, file_path)
  raise "File #{file_path} does not exist!" unless File.exists?(file_path)
  @em, @file_path = em, file_path
end

Instance Method Details

#start!Object



11
12
13
14
15
16
17
18
19
# File 'lib/empipelines/io_event_source.rb', line 11

def start!
  #TODO: this sucks hard, move to evented I/O
  events = IO.readlines(@file_path).map { |e| e.strip }

  wrapped_handler = BatchEventSource.new(@em, @file_path, events)
  wrapped_handler.on_event(event_handler)
  wrapped_handler.on_finished { |*ignored| finished! }
  wrapped_handler.start!
end