Class: Cinch::MessageQueue Private
- Inherits:
-
Object
- Object
- Cinch::MessageQueue
- Defined in:
- lib/cinch/message_queue.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class manages all outgoing messages, applying rate throttling and fair distribution.
Instance Method Summary collapse
-
#initialize(socket, bot) ⇒ MessageQueue
constructor
private
A new instance of MessageQueue.
-
#process!
private
-
#queue(message)
private
Constructor Details
#initialize(socket, bot) ⇒ MessageQueue
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MessageQueue.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cinch/message_queue.rb', line 10 def initialize(socket, bot) @socket = socket @bot = bot @queues = {:generic => OpenEndedQueue.new} @queues_to_process = Queue.new @queued_queues = Set.new @mutex = Mutex.new @time_since_last_send = nil @log = [] end |
Instance Method Details
#process!
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
56 57 58 59 60 61 |
# File 'lib/cinch/message_queue.rb', line 56 def process! loop do wait process_one end end |
#queue(message)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cinch/message_queue.rb', line 26 def queue() command, target, _ = .split(" ", 3) queue = nil case command when "PRIVMSG", "NOTICE" @mutex.synchronize do # we are assuming that each message has only one target, # which will be true as long as the user does not send raw # messages. # # this assumption is also reflected in the computation of # passed time and processed messages, since our score does # not take weights into account. queue = @queues[target] ||= OpenEndedQueue.new end else queue = @queues[:generic] end queue << @mutex.synchronize do unless @queued_queues.include?(queue) @queued_queues << queue @queues_to_process << queue end end end |