Class: SlackBotServer::LocalQueue
- Inherits:
-
Object
- Object
- SlackBotServer::LocalQueue
- Defined in:
- lib/slack_bot_server/local_queue.rb
Overview
A local implementation of a queue.
Obviously this can’t be used to communicate between multiple processes, let alone multiple machines, but it serves to demonstrate the expected API.
Instance Method Summary collapse
-
#clear ⇒ nil
Clear the queue.
-
#initialize ⇒ LocalQueue
constructor
Creates a new local in-memory queue.
-
#pop ⇒ Object?
Pop a value from the front of the queue.
-
#push(value) ⇒ Object
Push a value onto the back of the queue.
Constructor Details
#initialize ⇒ LocalQueue
Creates a new local in-memory queue
8 9 10 |
# File 'lib/slack_bot_server/local_queue.rb', line 8 def initialize @queue = Queue.new end |
Instance Method Details
#clear ⇒ nil
Clear the queue
27 28 29 |
# File 'lib/slack_bot_server/local_queue.rb', line 27 def clear @queue = Queue.new end |
#pop ⇒ Object?
Pop a value from the front of the queue
20 21 22 23 |
# File 'lib/slack_bot_server/local_queue.rb', line 20 def pop value = @queue.pop(true) rescue ThreadError value == ThreadError ? nil : value end |
#push(value) ⇒ Object
Push a value onto the back of the queue
13 14 15 |
# File 'lib/slack_bot_server/local_queue.rb', line 13 def push(value) @queue << value end |