123456789_123456789_123456789_123456789_123456789_

Class: Concurrent::Channel::Buffer::Timer

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Concurrent::Channel::Buffer::Base
Defined in: lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb

Class Method Summary

Base - Inherited

Instance Attribute Summary

Base - Inherited

#blocking?

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

#capacity

The maximum number of values which can be #put onto the buffer it becomes full.

#closed?

Predicate indicating is this buffer closed.

#empty?

Predicate indicating if the buffer is empty.

#full?

Predicate indicating if the buffer is full.

#size

The number of items currently in the buffer.

#buffer, #buffer=, #capacity=, #closed=,
#ns_closed?

Predicate indicating is this buffer closed.

#ns_empty?

Predicate indicating if the buffer is empty.

#ns_full?

Predicate indicating if the buffer is full.

#size=

Instance Method Summary

Base - Inherited

#close

Close the buffer, preventing new items from being added.

#next

Take the next “item” from the buffer and also return a boolean indicating if “more” items can be taken.

#offer

Put an item onto the buffer if possible.

#poll

Take the next item from the buffer if one is available else return immediately.

#put

Put an item onto the buffer if possible.

#take

Take an item from the buffer if one is available.

#ns_initialize,
#ns_size

The number of items currently in the buffer.

Synchronization::LockableObject - Inherited

Constructor Details

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

Instance Attribute Details

#ns_empty?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 56

def ns_empty?
  false
end

#ns_full?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 60

def ns_full?
  true
end

Instance Method Details

#do_poll (private)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 64

def do_poll
  synchronize do
    if ns_closed?
      return Concurrent::NULL, false
    elsif Concurrent.monotonic_time >= @tick
      # only one listener gets notified
      self.closed = true
      return Concurrent::Channel::Tick.new(@tick), false
    else
      return nil, true
    end
  end
end

#next

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 31

def next
  loop do
    tick, more = do_poll
    return tick, more if tick
    Thread.pass
  end
end

#ns_initialize(delay) (private)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 47

def ns_initialize(delay)
  @tick = Concurrent.monotonic_time + delay.to_f
  self.capacity = 1
end

#ns_size (private)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 52

def ns_size
  0
end

#offer(item)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 16

def offer(item)
  false
end

#poll

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 39

def poll
  tick, _ = do_poll
  tick = Concurrent::NULL unless tick
  tick
end

#put(item)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 12

def put(item)
  false
end

#take

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb', line 20

def take
  loop do
    tick, _ = do_poll
    if tick
      return tick
    else
      Thread.pass
    end
  end
end