Class: InternetScrabbleClub::Client::CallbackQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/internet_scrabble_club/client/callback_queue.rb

Instance Method Summary collapse

Constructor Details

#initializeCallbackQueue

Returns a new instance of CallbackQueue.



5
6
7
# File 'lib/internet_scrabble_club/client/callback_queue.rb', line 5

def initialize
  @queues = Hash.new { Array.new }
end

Instance Method Details

#dequeue(command, default = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/internet_scrabble_club/client/callback_queue.rb', line 13

def dequeue(command, default = nil)
  return @queues[command].shift if @queues[command].any?
  return yield(command) if block_given?
  return default unless default.nil?
  fail ArgumentError, "Missing callback handler for command #{command}"
end

#enqueue(command, callback) ⇒ Object



9
10
11
# File 'lib/internet_scrabble_club/client/callback_queue.rb', line 9

def enqueue(command, callback)
  @queues[command] += [callback]
end