Skip to content

Commit

Permalink
Add single threaded mode back in
Browse files Browse the repository at this point in the history
This is a slightly different implementation due to the use of promises
for both async and sync modes. The difference is whether the thread pool
is set to synchronous or not.
  • Loading branch information
MattFenelon committed May 24, 2024
1 parent 0971be7 commit c5680c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/graphiti/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ class Scope

# TODO: this could be a Concurrent::Promises.delay
GLOBAL_THREAD_POOL_EXECUTOR = Concurrent::Delay.new do
# concurrency = Graphiti.config.concurrency_max_threads || 4
Concurrent::ThreadPoolExecutor.new(max_threads: 0, synchronous: true, fallback_policy: :caller_runs)
if Graphiti.config.concurrency
concurrency = Graphiti.config.concurrency_max_threads || 4
Concurrent::ThreadPoolExecutor.new(
min_threads: 0,
max_threads: concurrency,
max_queue: concurrency * 4,
fallback_policy: :caller_runs
)
else
Concurrent::ThreadPoolExecutor.new(max_threads: 0, synchronous: true, fallback_policy: :caller_runs)
end
end
private_constant :GLOBAL_THREAD_POOL_EXECUTOR

Expand Down
2 changes: 1 addition & 1 deletion spec/scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
stub_const(
"Graphiti::Scope::GLOBAL_THREAD_POOL_EXECUTOR",
Concurrent::Delay.new do
Concurrent::ThreadPoolExecutor.new(max_threads: 1, fallback_policy: :caller_runs)
Concurrent::ThreadPoolExecutor.new(min_threads: 1, max_threads: 1, fallback_policy: :caller_runs)
end
)

Expand Down
2 changes: 1 addition & 1 deletion spec/sideloading_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def type
stub_const(
"Graphiti::Scope::GLOBAL_THREAD_POOL_EXECUTOR",
Concurrent::Delay.new do
Concurrent::ThreadPoolExecutor.new(max_threads: 0, synchronous: true, fallback_policy: :caller_runs)
Concurrent::ThreadPoolExecutor.new(min_threads: 1, max_threads: 1, fallback_policy: :caller_runs)
end
)

Expand Down

0 comments on commit c5680c3

Please sign in to comment.