Class: Datapipes::Pipe

Inherits:
Object
  • Object
show all
Defined in:
lib/datapipes/pipe.rb

Overview

Pipe is not only data pipeline but handling asynchronous.

You can make your own pipe with database or something, but becareful this object used in multi thread.

If you make your own, you can override initialize, because this is not used in internal.

Then supply pour_in and pour_out. pour_out must occur thread blocking when it is empty.

Instance Method Summary collapse

Constructor Details

#initializePipe

You can override and don’t need to call super in sub class.



14
15
16
# File 'lib/datapipes/pipe.rb', line 14

def initialize
  @queue ||= Queue.new
end

Instance Method Details

#pour_in(data) ⇒ Object

Emit data to pipe.



19
20
21
# File 'lib/datapipes/pipe.rb', line 19

def pour_in(data)
  @queue.enq data
end

#pour_outObject

pour_out must cause thread blocking when it is empty.



24
25
26
# File 'lib/datapipes/pipe.rb', line 24

def pour_out
  @queue.deq
end