@@ -19,7 +19,7 @@ module Concurrent
19
19
end . new
20
20
end
21
21
22
- context '#send_off ' do
22
+ context '#post_off ' do
23
23
subject { Agent . new 2 , executor : executor }
24
24
25
25
it 'executes post and post-off in order' do
@@ -28,6 +28,14 @@ module Concurrent
28
28
subject . await
29
29
expect ( subject . value ) . to eq 12
30
30
end
31
+
32
+ it 'times out' do
33
+ ex = nil
34
+ subject . post_off ( 0.1 ) { |v | sleep ( 0.2 ) ; ex = true }
35
+ subject . await
36
+ sleep 0.3
37
+ expect ( ex ) . to eq nil
38
+ end
31
39
end
32
40
33
41
context 'behavior' do
@@ -71,14 +79,6 @@ def trigger_observable(observable)
71
79
expect ( Agent . new ( 10 ) . value ) . to eq 10
72
80
end
73
81
74
- it 'sets the timeout to the given value' do
75
- expect ( Agent . new ( 0 , timeout : 5 ) . timeout ) . to eq 5
76
- end
77
-
78
- it 'sets the timeout to the default when nil' do
79
- expect ( Agent . new ( 0 ) . timeout ) . to eq Agent ::TIMEOUT
80
- end
81
-
82
82
it 'uses the executor given with the :executor option' do
83
83
expect ( executor ) . to receive ( :post ) . with ( any_args ) . and_return ( 0 )
84
84
agent = Agent . new ( 0 , executor : executor )
@@ -164,9 +164,9 @@ def trigger_observable(observable)
164
164
subject . post { nil }
165
165
sleep ( 0.1 )
166
166
expect ( subject .
167
- instance_variable_get ( :@serialized_execution ) .
168
- instance_variable_get ( :@stash ) .
169
- size ) . to eq 2
167
+ instance_variable_get ( :@serialized_execution ) .
168
+ instance_variable_get ( :@stash ) .
169
+ size ) . to eq 2
170
170
end
171
171
172
172
it 'does not add to the queue when no block is given' do
@@ -221,7 +221,7 @@ def trigger_observable(observable)
221
221
it 'passes the current value to the handler' do
222
222
latch = Concurrent ::CountDownLatch . new ( 5 )
223
223
Agent . new ( latch . count , executor : executor ) . post do |i |
224
- i . times { latch . count_down }
224
+ i . times { latch . count_down }
225
225
end
226
226
expect ( latch . wait ( 1 ) ) . to be_truthy
227
227
end
@@ -252,7 +252,7 @@ def trigger_observable(observable)
252
252
253
253
it 'passes the new value to the validator' do
254
254
expected = Concurrent ::AtomicFixnum . new ( 0 )
255
- latch = Concurrent ::CountDownLatch . new ( 1 )
255
+ latch = Concurrent ::CountDownLatch . new ( 1 )
256
256
subject . validate { |v | expected . value = v ; latch . count_down ; true }
257
257
subject . post { 10 }
258
258
latch . wait ( 1 )
@@ -282,7 +282,7 @@ def trigger_observable(observable)
282
282
283
283
it 'calls the first exception block with a matching class' do
284
284
expected = nil
285
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
285
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
286
286
rescue ( StandardError ) { |ex | expected = 1 } .
287
287
rescue ( StandardError ) { |ex | expected = 2 } .
288
288
rescue ( StandardError ) { |ex | expected = 3 }
@@ -292,7 +292,7 @@ def trigger_observable(observable)
292
292
293
293
it 'matches all with a rescue with no class given' do
294
294
expected = nil
295
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
295
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
296
296
rescue ( LoadError ) { |ex | expected = 1 } .
297
297
rescue { |ex | expected = 2 } .
298
298
rescue ( StandardError ) { |ex | expected = 3 }
@@ -302,23 +302,23 @@ def trigger_observable(observable)
302
302
303
303
it 'searches associated rescue handlers in order' do
304
304
expected = nil
305
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
305
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
306
306
rescue ( ArgumentError ) { |ex | expected = 1 } .
307
307
rescue ( LoadError ) { |ex | expected = 2 } .
308
308
rescue ( StandardError ) { |ex | expected = 3 }
309
309
agent . post { raise ArgumentError }
310
310
expect ( expected ) . to eq 1
311
311
312
312
expected = nil
313
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
313
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
314
314
rescue ( ArgumentError ) { |ex | expected = 1 } .
315
315
rescue ( LoadError ) { |ex | expected = 2 } .
316
316
rescue ( StandardError ) { |ex | expected = 3 }
317
317
agent . post { raise LoadError }
318
318
expect ( expected ) . to eq 2
319
319
320
320
expected = nil
321
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
321
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
322
322
rescue ( ArgumentError ) { |ex | expected = 1 } .
323
323
rescue ( LoadError ) { |ex | expected = 2 } .
324
324
rescue ( StandardError ) { |ex | expected = 3 }
@@ -328,7 +328,7 @@ def trigger_observable(observable)
328
328
329
329
it 'passes the exception object to the matched block' do
330
330
expected = nil
331
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
331
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
332
332
rescue ( ArgumentError ) { |ex | expected = ex } .
333
333
rescue ( LoadError ) { |ex | expected = ex } .
334
334
rescue ( StandardError ) { |ex | expected = ex }
@@ -338,7 +338,7 @@ def trigger_observable(observable)
338
338
339
339
it 'ignores rescuers without a block' do
340
340
expected = nil
341
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
341
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new ) .
342
342
rescue ( StandardError ) .
343
343
rescue ( StandardError ) { |ex | expected = ex }
344
344
agent . post { raise StandardError }
@@ -464,15 +464,15 @@ def trigger_observable(observable)
464
464
end
465
465
466
466
it 'aliases #catch for #rescue' do
467
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new )
467
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new )
468
468
expected = nil
469
469
agent . catch { expected = true }
470
470
agent . post { raise StandardError }
471
471
expect ( agent ) . to be_truthy
472
472
end
473
473
474
474
it 'aliases #on_error for #rescue' do
475
- agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new )
475
+ agent = Agent . new ( 0 , executor : Concurrent ::ImmediateExecutor . new )
476
476
expected = nil
477
477
agent . on_error { expected = true }
478
478
agent . post { raise StandardError }
0 commit comments