class ThreadComm
Thread with communication queues for simple messaging
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/nub/thread_comm.rb, line 29 def initialize @comm_in = Queue.new @comm_out = Queue.new # Proc.new will return the block given to this method # pass it along to thread .new with arguments super(@comm_in, @comm_out, &Proc.new) end
Public Instance Methods
empty?()
click to toggle source
Check if the message queue is empty
# File lib/nub/thread_comm.rb, line 39 def empty? return @comm_out.empty? end
pop()
click to toggle source
Pop a message off the thread's outbound queue or block
# File lib/nub/thread_comm.rb, line 44 def pop msg = @comm_out.pop return msg if msg.is_a?(ThreadMsg) return ThreadMsg.new(msg) end
push(*args)
click to toggle source
Push the given message onto the threads inbound queue @param msg [ThreadMsg] message to the thread @param cmd [String] message command to the thread @param value [String] message value to the thread
# File lib/nub/thread_comm.rb, line 54 def push(*args) if args.first.is_a?(ThreadMsg) @comm_in << args.first elsif args.size == 1 @comm_in << ThreadMsg.new(args.first) else @comm_in << ThreadMsg.new(args.first, args.last) end end