Skip to content

Commit 041196d

Browse files
author
Petr Chalupa
committed
Merge pull request #175 from ruby-concurrency/actress
Forbid ImmediateExecutor for Actors
2 parents eefb242 + 4db099d commit 041196d

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/concurrent/actor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.spawn(*args, &block)
7070
if Actor.current
7171
Core.new(spawn_optionify(*args).merge(parent: Actor.current), &block).reference
7272
else
73-
root.ask([:spawn, spawn_optionify(*args), block]).value
73+
root.ask([:spawn, spawn_optionify(*args), block]).value!
7474
end
7575
end
7676

lib/concurrent/actor/core.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ def initialize(opts = {}, &block)
4646
synchronize do
4747
@mailbox = Array.new
4848
@serialized_execution = SerializedExecution.new
49-
@executor = Type! opts.fetch(:executor, Concurrent.configuration.global_task_pool), Executor
5049
@children = Set.new
51-
@context_class = Child! opts.fetch(:class), AbstractContext
50+
51+
@context_class = Child! opts.fetch(:class), AbstractContext
5252
allocate_context
53+
54+
@executor = Type! opts.fetch(:executor, Concurrent.configuration.global_task_pool), Executor
55+
raise ArgumentError, 'ImmediateExecutor is not supported' if @executor.is_a? ImmediateExecutor
56+
5357
@reference = (Child! opts[:reference_class] || @context.default_reference_class, Reference).new self
5458
@name = (Type! opts.fetch(:name), String, Symbol).to_s
5559

@@ -82,7 +86,7 @@ def initialize(opts = {}, &block)
8286
handle_envelope Envelope.new(message, nil, parent, reference)
8387
end
8488

85-
initialized.set true if initialized
89+
initialized.set reference if initialized
8690
rescue => ex
8791
log ERROR, ex
8892
@first_behaviour.terminate!

spec/concurrent/actor_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def on_message(message)
5454
# set_trace_func nil
5555
# end
5656

57+
it 'forbids Immediate executor' do
58+
expect { Utils::AdHoc.spawn name: 'test', executor: ImmediateExecutor.new }.to raise_error
59+
end
60+
5761
describe 'stress test' do
5862
1.times do |i|
5963
it format('run %3d', i) do

0 commit comments

Comments
 (0)