Sha256: b14ca09f4c311672fddfec663d21f48de7984644a1295b859a9dcf1c3f478981

Contents?: true

Size: 1.5 KB

Versions: 18

Compression:

Stored size: 1.5 KB

Contents

require 'concurrent/constants'
require 'concurrent/utility/monotonic_time'
require 'concurrent/channel/tick'
require 'concurrent/channel/buffer/base'

module Concurrent
  class Channel
    module Buffer

      class Timer < Base

        def put(item)
          false
        end

        def offer(item)
          false
        end

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

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

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

        private

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

        def ns_size
          0
        end

        def ns_empty?
          false
        end

        def ns_full?
          true
        end

        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
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
concurrent-ruby-edge-0.7.2 lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.7.1 lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.7.0 lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.6.0 lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.6.0.pre1 lib/concurrent-ruby-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.5.0 lib-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.4.1 lib-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.4.0.pre2 lib-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.4.0.pre1 lib-edge/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.2.4 lib/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.3.1 lib/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.3.0 lib/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.2.3 lib/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.2.3.pre3 lib/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.2.2 lib/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.2.1 lib/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.2.0 lib/concurrent/channel/buffer/timer.rb
concurrent-ruby-edge-0.2.0.pre5 lib/concurrent/channel/buffer/timer.rb