class Thread::Pipe::Task
A task encapsulates a part of the pipe.
Attributes
input[RW]
output[RW]
Public Class Methods
new(func, input = Queue.new, output = Queue.new)
click to toggle source
Create a Task
which will call the passed function and get input from the optional parameter and put output in the optional parameter.
# 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
Public Instance Methods
empty?()
click to toggle source
Check if the task has nothing to do.
# File lib/thread/pipe.rb, line 43 def empty? !@handling && @input.empty? && @output.empty? end
kill()
click to toggle source
Stop the task.
# File lib/thread/pipe.rb, line 48 def kill @thread.raise end