Sha256: 8c0cd66f23b6f4dc491dd28971006e9ab7acaa05336edca18ad10c99a5ea4060

Contents?: true

Size: 663 Bytes

Versions: 97

Compression:

Stored size: 663 Bytes

Contents

module Listen

  # Allows two threads to wait on eachother.
  #
  # @note Only two threads can be used with this Turnstile
  #   because of the current implementation.
  class Turnstile
    attr_accessor :queue

    # Initialize the turnstile.
    #
    def initialize
      # Until Ruby offers semahpores, only queues can be used
      # to implement a turnstile.
      @queue = Queue.new
    end

    # Blocks the current thread until a signal is received.
    #
    def wait
      queue.pop if queue.num_waiting == 0
    end

    # Unblocks the waiting thread if any.
    #
    def signal
      queue.push(:dummy) if queue.num_waiting == 1
    end

  end

end

Version data entries

97 entries across 94 versions & 8 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.4.0 bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.3.1 bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.3.0 bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.2.1 bundle/ruby/2.5.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.2.0 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.1.1 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.1.0 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.0.1 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.0.1.pre1 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-4.0.0 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-3.7.2 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/sass-3.4.25/vendor/listen/lib/listen/turnstile.rb
sass-3.4.25 vendor/listen/lib/listen/turnstile.rb
brakeman-3.7.0 bundle/ruby/2.3.0/gems/sass-3.4.24/vendor/listen/lib/listen/turnstile.rb
brakeman-3.6.2 bundle/ruby/2.3.0/gems/sass-3.4.24/vendor/listen/lib/listen/turnstile.rb
sass-3.4.24 vendor/listen/lib/listen/turnstile.rb
brakeman-3.6.1 bundle/ruby/2.3.0/gems/sass-3.4.23/vendor/listen/lib/listen/turnstile.rb
brakeman-3.6.0 bundle/ruby/2.3.0/gems/sass-3.4.23/vendor/listen/lib/listen/turnstile.rb
brakeman-3.5.0 bundle/ruby/2.3.0/gems/sass-3.4.23/vendor/listen/lib/listen/turnstile.rb