Sha256: a829f7da798f14f1c31ee1f253fe5fe48361eb87708e9181c1f827d60652331a

Contents?: true

Size: 786 Bytes

Versions: 6

Compression:

Stored size: 786 Bytes

Contents

require 'concurrent/synchronization'

module Concurrent
  module Channel

    # @api Channel
    # @!macro edge_warning
    class WaitableList < Synchronization::Object

      def initialize
        super()
        synchronize { ns_initialize }
      end

      def size
        synchronize { @list.size }
      end

      def empty?
        synchronize { @list.empty? }
      end

      def put(value)
        synchronize do
          @list << value
          ns_signal
        end
      end

      def delete(value)
        synchronize { @list.delete(value) }
      end

      def take
        synchronize do
          ns_wait_until { !@list.empty? }
          @list.shift
        end
      end

      protected

      def ns_initialize
        @list = []
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
concurrent-ruby-edge-0.1.2 lib/concurrent/channel/waitable_list.rb
concurrent-ruby-edge-0.2.0.pre1 lib/concurrent/channel/waitable_list.rb
concurrent-ruby-edge-0.1.1 lib/concurrent/channel/waitable_list.rb
concurrent-ruby-edge-0.1.0 lib/concurrent/channel/waitable_list.rb
concurrent-ruby-edge-0.1.0.pre3 lib/concurrent/channel/waitable_list.rb
concurrent-ruby-edge-0.1.0.pre2 lib/concurrent/channel/waitable_list.rb