Class: Concurrent::Channel::Buffer::Sliding

Inherits:
Buffered
  • Object
show all
Defined in:
lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb

Overview

A non-blocking, buffered buffer of fixed maximum capacity. When the maximum capacity is reached subsequent #put and #offer operations will complete and the item will be ‘put`, but the oldest elements in the buffer will be discarded (not transferred).

Instance Attribute Summary

Attributes inherited from Base

#capacity

Instance Method Summary collapse

Methods inherited from Buffered

#next, #poll, #take

Methods inherited from Base

#close, #closed?, #empty?, #initialize, #next, #poll, #size, #take

Constructor Details

This class inherits a constructor from Concurrent::Channel::Buffer::Base

Instance Method Details

#blocking?Boolean

Predicate indicating if this buffer will block #put operations once it reaches its maximum capacity.

Always returns ‘false`.

Returns:

  • (Boolean)

    true if this buffer blocks else false



36
37
38
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb', line 36

def blocking?
  false
end

#full?Boolean

Predicate indicating if the buffer is full.

Always returns ‘false`.

Returns:

  • (Boolean)

    true if this buffer is full else false



# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb', line 28

#offer(item) ⇒ Boolean

Put an item onto the buffer if possible. If the buffer is open but unable to add an item, probably due to being full, the method will return immediately. Similarly, the method will return immediately when the buffer is closed. A return value of ‘false` does not necessarily indicate that the buffer is closed, just that the item could not be added.

When the buffer is full, this method will return ‘true` immediately and the item will be inserted, but the oldest elements in the buffer will be discarded (not transferred).

Parameters:

  • item (Object)

    the item/value to put onto the buffer.

Returns:

  • (Boolean)

    true if the item was added to the buffer else false (always false when closed).



# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb', line 21

#put(item) ⇒ Boolean

Put an item onto the buffer if possible. If the buffer is open but not able to accept the item the calling thread will block until the item can be put onto the buffer.

When the buffer is full, this method will return ‘true` immediately and the item will be inserted, but the oldest elements in the buffer will be discarded (not transferred).

Parameters:

  • item (Object)

    the item/value to put onto the buffer.

Returns:

  • (Boolean)

    true if the item was added to the buffer else false (always false when closed).



# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb', line 14