Sha256: e1ee44209d6e77b076955a735a86cde9ab3c89757499a2285371d4731085fbc0

Contents?: true

Size: 1.8 KB

Versions: 314

Compression:

Stored size: 1.8 KB

Contents

require 'concurrent/atomic/event'
require 'concurrent/executor/abstract_executor_service'
require 'concurrent/executor/serial_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 < AbstractExecutorService
    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

314 entries across 289 versions & 56 rubygems

Version Path
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb