Sha256: a4468cb2545250cafb06a1460c185031275fc58b23920a5d8d9df6e4725e98c3

Contents?: true

Size: 1.49 KB

Versions: 163

Compression:

Stored size: 1.49 KB

Contents

require 'concurrent/executor/abstract_executor_service'
require 'concurrent/atomic/event'

module Concurrent

  # @!macro abstract_executor_service_public_api
  # @!visibility private
  class RubyExecutorService < AbstractExecutorService
    safe_initialization!

    def initialize(*args, &block)
      super
      @StopEvent    = Event.new
      @StoppedEvent = Event.new
    end

    def post(*args, &task)
      raise ArgumentError.new('no block given') unless block_given?
      synchronize do
        # If the executor is shut down, reject this task
        return handle_fallback(*args, &task) unless running?
        ns_execute(*args, &task)
        true
      end
    end

    def shutdown
      synchronize do
        break unless running?
        self.ns_auto_terminate = false
        stop_event.set
        ns_shutdown_execution
      end
      true
    end

    def kill
      synchronize do
        break if shutdown?
        self.ns_auto_terminate = false
        stop_event.set
        ns_kill_execution
        stopped_event.set
      end
      true
    end

    def wait_for_termination(timeout = nil)
      stopped_event.wait(timeout)
    end

    private

    def stop_event
      @StopEvent
    end

    def stopped_event
      @StoppedEvent
    end

    def ns_shutdown_execution
      stopped_event.set
    end

    def ns_running?
      !stop_event.set?
    end

    def ns_shuttingdown?
      !(ns_running? || ns_shutdown?)
    end

    def ns_shutdown?
      stopped_event.set?
    end
  end
end

Version data entries

163 entries across 150 versions & 33 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_executor_service.rb