Sha256: a6b7a63d3e6d57504d46eb08c33d800db7bc95cc6be03380cba2a0e6f9f5109c

Contents?: true

Size: 1.47 KB

Versions: 115

Compression:

Stored size: 1.47 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?
      deferred_action = synchronize {
        if running?
          ns_execute(*args, &task)
        else
          fallback_action(*args, &task)
        end
      }
      if deferred_action
        deferred_action.call
      else
        true
      end
    end

    def shutdown
      synchronize do
        break unless running?
        stop_event.set
        ns_shutdown_execution
      end
      true
    end

    def kill
      synchronize do
        break if shutdown?
        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

115 entries across 113 versions & 19 rubygems

Version Path
concurrent-ruby-1.3.5 lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.3.3/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.4/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.4/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.4/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
concurrent-ruby-1.3.4 lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.3/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.3.3/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.3/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
concurrent-ruby-1.3.3 lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
concurrent-ruby-1.3.2 lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.1/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
concurrent-ruby-1.3.1 lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
concurrent-ruby-1.3.1.pre lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb
concurrent-ruby-1.2.3 lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb