Class: SlackBotServer::LocalQueue

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeLocalQueue

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

#clearnil

Clear the queue

Returns:

  • (nil)


27
28
29
# File 'lib/slack_bot_server/local_queue.rb', line 27

def clear
  @queue = Queue.new
end

#popObject?

Pop a value from the front of the queue

Returns:

  • (Object, nil)

    returns the object from the front of the queue, or nil if the queue is empty



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