File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -81,13 +81,15 @@ def value(timeout = nil)
81
81
# this function has been optimized for performance and
82
82
# should not be modified without running new benchmarks
83
83
synchronize do
84
- execute = @computing = true unless @computing
84
+ execute = @evaluation_started = true unless @evaluation_started
85
85
if execute
86
86
begin
87
87
set_state ( true , @task . call , nil )
88
88
rescue => ex
89
89
set_state ( false , nil , ex )
90
90
end
91
+ elsif incomplete?
92
+ raise IllegalOperationError , 'Recursive call to #value during evaluation of the Delay'
91
93
end
92
94
end
93
95
if @do_nothing_on_deref
@@ -144,7 +146,7 @@ def wait(timeout = nil)
144
146
def reconfigure ( &block )
145
147
synchronize do
146
148
raise ArgumentError . new ( 'no block given' ) unless block_given?
147
- unless @computing
149
+ unless @evaluation_started
148
150
@task = block
149
151
true
150
152
else
@@ -160,9 +162,9 @@ def ns_initialize(opts, &block)
160
162
set_deref_options ( opts )
161
163
@executor = opts [ :executor ]
162
164
163
- @task = block
164
- @state = :pending
165
- @computing = false
165
+ @task = block
166
+ @state = :pending
167
+ @evaluation_started = false
166
168
end
167
169
168
170
private
@@ -173,7 +175,7 @@ def execute_task_once # :nodoc:
173
175
# should not be modified without running new benchmarks
174
176
execute = task = nil
175
177
synchronize do
176
- execute = @computing = true unless @computing
178
+ execute = @evaluation_started = true unless @evaluation_started
177
179
task = @task
178
180
end
179
181
Original file line number Diff line number Diff line change @@ -85,6 +85,18 @@ def dereferenceable_subject(value, opts = {})
85
85
delay = Delay . new ( &task )
86
86
5 . times { delay . value }
87
87
end
88
+
89
+ it 'raises when called recursively' do
90
+ delay = Delay . new { delay . value }
91
+ expect { delay . value! } . to raise_error ( IllegalOperationError )
92
+ expect ( delay . reason ) . to be_a_kind_of ( IllegalOperationError )
93
+ end
94
+
95
+ it 'can be called twice' do
96
+ delay = Delay . new { 10 }
97
+ expect ( delay . value ) . to eq 10
98
+ expect ( delay . value ) . to eq 10
99
+ end
88
100
end
89
101
end
90
102
end
You can’t perform that action at this time.
0 commit comments