Skip to content

Commit 0c05bce

Browse files
committed
Delay with no constructor options now uses ImmediateExecutor.
1 parent 9341b09 commit 0c05bce

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lib/concurrent/configuration.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ module Concurrent
4444
end
4545
private_constant :GLOBAL_TIMER_SET
4646

47+
# @!visibility private
48+
GLOBAL_IMMEDIATE_EXECUTOR = ImmediateExecutor.new
49+
4750
def self.global_logger
4851
GLOBAL_LOGGER.value
4952
end

lib/concurrent/delay.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'concurrent/configuration'
33
require 'concurrent/obligation'
44
require 'concurrent/executor/executor_options'
5+
require 'concurrent/executor/immediate_executor'
56

67
module Concurrent
78

@@ -56,7 +57,7 @@ def initialize(opts = {}, &block)
5657
@state = :pending
5758
@task = block
5859
set_deref_options(opts)
59-
@task_executor = get_executor_from(opts) || Concurrent.global_io_executor
60+
@task_executor = get_executor_from(opts) || Concurrent::GLOBAL_IMMEDIATE_EXECUTOR
6061
@computing = false
6162
end
6263

spec/concurrent/delay_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ def dereferenceable_subject(value, opts = {})
2222
let!(:rejected_reason) { StandardError.new('mojo jojo') }
2323

2424
let(:pending_subject) do
25-
Delay.new{ sleep 0.05; fulfilled_value }
25+
Delay.new(executor: :fast){ sleep 0.05; fulfilled_value }
2626
end
2727

2828
let(:fulfilled_subject) do
29-
delay = Delay.new{ fulfilled_value }
29+
delay = Delay.new(executor: :fast){ fulfilled_value }
3030
delay.tap{ delay.value }
3131
end
3232

3333
let(:rejected_subject) do
34-
delay = Delay.new{ raise rejected_reason }
34+
delay = Delay.new(executor: :fast){ raise rejected_reason }
3535
delay.tap{ delay.value }
3636
end
3737

0 commit comments

Comments
 (0)