Sha256: 01e82af771a6485a70ebfb8a43864458750f233678571deab489e4890f2827bf

Contents?: true

Size: 1.54 KB

Versions: 335

Compression:

Stored size: 1.54 KB

Contents

require 'concurrent/executor/immediate_executor'
require 'concurrent/executor/simple_executor_service'

module Concurrent
  # An executor service which runs all operations on a new thread, blocking
  # until it completes. 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 a new thread, blocking the
  # current thread until the operation is complete. This is similar to how the
  # ImmediateExecutor works, but the operation has the full stack of the new
  # thread at its disposal. This can be helpful when the operations will spawn
  # more operations on the same executor and so on - such a situation might
  # overflow the single stack in case of an ImmediateExecutor, which is
  # inconsistent with how it would behave for a threaded executor.
  #
  # @note Intended for use primarily in testing and debugging.
  class IndirectImmediateExecutor < ImmediateExecutor
    # Creates a new executor
    def initialize
      super
      @internal_executor = SimpleExecutorService.new
    end

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

      event = Concurrent::Event.new
      @internal_executor.post do
        begin
          task.call(*args)
        ensure
          event.set
        end
      end
      event.wait

      true
    end
  end
end

Version data entries

335 entries across 305 versions & 59 rubygems

Version Path
harbr-0.1.46 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
harbr-0.1.45 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
harbr-0.1.44 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
harbr-0.1.43 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
harbr-0.1.42 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
harbr-0.1.41 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
harbr-0.1.39 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
harbr-0.1.38 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
harbr-0.1.37 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb