Class: Cinch::MessageQueue Private
- Inherits:
-
Object
- Object
- Cinch::MessageQueue
- Defined in:
- lib/cinch/message_queue.rb
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.
Instance Method Summary collapse
-
#initialize(socket, bot) ⇒ MessageQueue
constructor
private
A new instance of MessageQueue.
- #process! ⇒ void private
- #queue(message) ⇒ void 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.
7 8 9 10 11 12 13 14 |
# File 'lib/cinch/message_queue.rb', line 7 def initialize(socket, bot) @socket = socket @queue = Queue.new @time_since_last_send = nil @bot = bot @log = [] end |
Instance Method Details
#process! ⇒ void
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.
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 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cinch/message_queue.rb', line 28 def process! while true mps = @bot.config. max_queue_size = @bot.config.server_queue_size if @log.size > 1 time_passed = 0 @log.each_with_index do |one, index| second = @log[index+1] time_passed += second - one break if index == @log.size - 2 end = (time_passed * mps).floor effective_size = @log.size - if effective_size <= 0 @log.clear elsif effective_size >= max_queue_size sleep 1.0/mps end end = @queue.pop.to_s.chomp begin @socket.writeline Cinch.encode_outgoing(, @bot.config.encoding) + "\r\n" @log << Time.now @bot.logger.log(, :outgoing) if @bot.config.verbose @time_since_last_send = Time.now rescue IOError @bot.debug "Could not send message (connectivity problems): #{}" end end end |
#queue(message) ⇒ void
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.
17 18 19 20 21 22 23 24 25 |
# File 'lib/cinch/message_queue.rb', line 17 def queue() command = .split(" ").first if command == "PONG" @queue.unshift() else @queue << end end |