Class: StatelyDB::Transaction::Queue

Inherits:
Thread::Queue
  • Object
show all
Defined in:
lib/transaction/queue.rb

Overview

TransactionQueue is a wrapper around Thread::Queue that implements Enumerable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQueue

Returns a new instance of Queue.



11
12
13
14
# File 'lib/transaction/queue.rb', line 11

def initialize
  super
  @last_message_id = 0
end

Instance Attribute Details

#last_message_idInteger? (readonly)

Returns The ID of the last message, or nil if there is no message.

Returns:

  • (Integer, nil)

    The ID of the last message, or nil if there is no message.



9
10
11
# File 'lib/transaction/queue.rb', line 9

def last_message_id
  @last_message_id
end

Instance Method Details

#each {|Object| ... } ⇒ void

This method returns an undefined value.

Iterates over each element in the queue, yielding each element to the given block.

Yields:

  • (Object)

    Gives each element in the queue to the block.



27
28
29
30
31
# File 'lib/transaction/queue.rb', line 27

def each
  loop do
    yield pop
  end
end

#each_item {|Object| ... } ⇒ void

This method returns an undefined value.

Iterates over each item in the queue, yielding each item to the given block.

Yields:

  • (Object)

    Gives each item in the queue to the block.



37
38
39
40
41
# File 'lib/transaction/queue.rb', line 37

def each_item
  loop do
    yield pop
  end
end

#next_message_idInteger

next_message_id returns the next message ID, which is the current size of the queue + 1. This value is consumed by the StatelyDB transaction as a monotonically increasing MessageID.

Returns:

  • (Integer)


19
20
21
# File 'lib/transaction/queue.rb', line 19

def next_message_id
  @last_message_id += 1
end