Method: Thread::Pipe::Task#initialize
- Defined in:
- lib/thread/pipe.rb
#initialize(func, input = Queue.new, output = Queue.new) ⇒ Task
Create a Task which will call the passed function and get input from the optional parameter and put output in the optional parameter.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/thread/pipe.rb', line 23 def initialize(func, input = Queue.new, output = Queue.new) @input = input @output = output @handling = false @thread = Thread.new { while true value = @input.deq @handling = true begin value = func.call(value) @output.enq value rescue Exception; end @handling = false end } end |