Class: ForgetfulQueue

Inherits:
Queue
  • Object
show all
Defined in:
lib/autumn/misc.rb

Overview

An implementation of SizedQueue that, instead of blocking when the queue is full, simply discards the overflow, forgetting it.

Instance Method Summary collapse

Constructor Details

#initialize(capacity) ⇒ ForgetfulQueue

Creates a new sized queue.



56
57
58
# File 'lib/autumn/misc.rb', line 56

def initialize(capacity)
  @max = capacity
end

Instance Method Details

#full?Boolean

Returns true if this queue is at maximum size.

Returns:

  • (Boolean)


62
63
64
# File 'lib/autumn/misc.rb', line 62

def full?
  size == @max
end

#push(obj) ⇒ Object Also known as: <<, enq

Pushes an object onto the queue. If there is no space left on the queue, does nothing.



69
70
71
# File 'lib/autumn/misc.rb', line 69

def push(obj)
  Thread.exclusive { super unless full? }
end