Sha256: f74444cee1a1cf5023c31ccc38bf79610bc0c25cad99c816b831b7f327198e65

Contents?: true

Size: 1.71 KB

Versions: 21

Compression:

Stored size: 1.71 KB

Contents

require 'concurrent/atomic/event'
require 'concurrent/executor/executor_service'

module Concurrent

  # An executor service which runs all operations on the current thread,
  # blocking as necessary. Operations are performed in the order they are
  # received and no two operations can be performed simultaneously.
  #
  # This executor service exists mainly for testing an debugging. When used
  # it immediately runs every `#post` operation on the current thread, blocking
  # that thread until the operation is complete. This can be very beneficial
  # during testing because it makes all operations deterministic.
  #
  # @note Intended for use primarily in testing and debugging.
  class ImmediateExecutor
    include SerialExecutorService

    # Creates a new executor
    def initialize
      @stopped = Concurrent::Event.new
    end

    # @!macro executor_service_method_post
    def post(*args, &task)
      raise ArgumentError.new('no block given') unless block_given?
      return false unless running?
      task.call(*args)
      true
    end

    # @!macro executor_service_method_left_shift
    def <<(task)
      post(&task)
      self
    end

    # @!macro executor_service_method_running_question
    def running?
      ! shutdown?
    end

    # @!macro executor_service_method_shuttingdown_question
    def shuttingdown?
      false
    end

    # @!macro executor_service_method_shutdown_question
    def shutdown?
      @stopped.set?
    end

    # @!macro executor_service_method_shutdown
    def shutdown
      @stopped.set
      true
    end
    alias_method :kill, :shutdown

    # @!macro executor_service_method_wait_for_termination
    def wait_for_termination(timeout = nil)
      @stopped.wait(timeout)
    end
  end
end

Version data entries

21 entries across 19 versions & 5 rubygems

Version Path
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/concurrent-ruby-0.9.2-java/lib/concurrent/executor/immediate_executor.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/concurrent-ruby-0.9.2-java/lib/concurrent/executor/immediate_executor.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/concurrent-ruby-0.9.2-java/lib/concurrent/executor/immediate_executor.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/concurrent-ruby-0.9.2-java/lib/concurrent/executor/immediate_executor.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/concurrent-ruby-0.9.2-java/lib/concurrent/executor/immediate_executor.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/concurrent-ruby-0.9.2-java/lib/concurrent/executor/immediate_executor.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/concurrent-ruby-0.9.1-java/lib/concurrent/executor/immediate_executor.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/concurrent-ruby-0.9.1-java/lib/concurrent/executor/immediate_executor.rb
logstash-codec-json-2.0.3 vendor/gems/concurrent-ruby-0.9.1-java/lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.2-java lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.2 lib/concurrent/executor/immediate_executor.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/concurrent-ruby-0.9.1-java/lib/concurrent/executor/immediate_executor.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/concurrent-ruby-0.9.1-java/lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.1 lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.1-java lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.0 lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.0-java lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.0.pre3-java lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.0.pre3 lib/concurrent/executor/immediate_executor.rb
concurrent-ruby-0.9.0.pre2 lib/concurrent/executor/immediate_executor.rb