File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ require 'concurrent/executor/executor'
2+
3+ module Concurrent
4+ # An executor service which runs all operations on a new thread, blocking
5+ # until it completes. Operations are performed in the order they are received
6+ # and no two operations can be performed simultaneously.
7+ #
8+ # This executor service exists mainly for testing an debugging. When used it
9+ # immediately runs every `#post` operation on a new thread, blocking the
10+ # current thread until the operation is complete. This is similar to how the
11+ # ImmediateExecutor works, but the operation has the full stack of the new
12+ # thread at its disposal. This can be helpful when the operations will spawn
13+ # more operations on the same executor and so on - such a situation might
14+ # overflow the single stack in case of an ImmediateExecutor, which is
15+ # inconsistent with how it would behave for a threaded executor.
16+ #
17+ # @note Intended for use primarily in testing and debugging.
18+ class IndirectImmediateExecutor < ImmediateExecutor
19+ # @!macro executor_method_post
20+ def post ( *args , &task )
21+ return false unless running?
22+
23+ executor = SingleThreadExecutor . new
24+ executor . post ( *args , &task )
25+ executor . shutdown
26+ executor . wait_for_termination
27+ true
28+ end
29+ end
30+ end
Original file line number Diff line number Diff line change 11require 'concurrent/executor/cached_thread_pool'
22require 'concurrent/executor/fixed_thread_pool'
33require 'concurrent/executor/immediate_executor'
4+ require 'concurrent/executor/indirect_immediate_executor'
45require 'concurrent/executor/per_thread_executor'
56require 'concurrent/executor/safe_task_executor'
67require 'concurrent/executor/single_thread_executor'
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+ require_relative 'executor_service_shared'
3+
4+ module Concurrent
5+
6+ describe IndirectImmediateExecutor do
7+
8+ subject { IndirectImmediateExecutor . new }
9+
10+ it_should_behave_like :executor_service
11+ end
12+ end
You can’t perform that action at this time.
0 commit comments