File tree Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ group :testing do
13
13
gem 'simplecov' , '~> 0.9.2' , :require => false
14
14
gem 'coveralls' , '~> 0.7.11' , :require => false
15
15
gem 'timecop' , '~> 0.7.3'
16
- gem 'hitimes' , '~> 1.2.2'
17
16
end
18
17
19
18
group :documentation do
Original file line number Diff line number Diff line change @@ -55,6 +55,22 @@ def monotonic_time
55
55
GLOBAL_MONOTONIC_CLOCK . get_time
56
56
end
57
57
module_function :monotonic_time
58
+
59
+ # Runs the given block and returns the number of seconds that elapsed.
60
+ #
61
+ # @yield the block to run and time
62
+ # @return [Float] the number of seconds the block took to run
63
+ #
64
+ # @raise [ArgumentError] when no block given
65
+ #
66
+ # @!macro monotonic_clock_warning
67
+ def monotonic_interval
68
+ raise ArgumentError . new ( 'no block given' ) unless block_given?
69
+ start_time = GLOBAL_MONOTONIC_CLOCK . get_time
70
+ yield
71
+ GLOBAL_MONOTONIC_CLOCK . get_time - start_time
72
+ end
73
+ module_function :monotonic_interval
58
74
end
59
75
60
76
__END__
Original file line number Diff line number Diff line change 1
- require 'hitimes'
2
-
3
1
module Concurrent
4
2
5
3
describe Exchanger do
@@ -58,7 +56,7 @@ module Concurrent
58
56
context 'with timeout' do
59
57
60
58
it 'should block until timeout' do
61
- duration = Hitimes :: Interval . measure do
59
+ duration = Concurrent . monotonic_interval do
62
60
subject . exchange ( 2 , 0.1 )
63
61
end
64
62
expect ( duration ) . to be_within ( 0.05 ) . of ( 0.1 )
Original file line number Diff line number Diff line change 1
- require 'hitimes'
2
-
3
1
module Concurrent
4
2
5
3
describe '#timer' do
@@ -17,12 +15,8 @@ module Concurrent
17
15
end
18
16
19
17
it 'executes the block after the given number of seconds' do
20
- latch = CountDownLatch . new ( 1 )
21
- duration = Hitimes ::Interval . measure do
22
- Concurrent ::timer ( 0.2 ) { latch . count_down }
23
- latch . wait ( 1 )
24
- end
25
- expect ( duration ) . to be_within ( 0.1 ) . of ( 0.2 )
18
+ expect ( Concurrent . configuration . global_timer_set ) . to receive ( :post ) . with ( 0.1 )
19
+ Concurrent ::timer ( 0.1 ) { nil }
26
20
end
27
21
28
22
it 'suppresses exceptions thrown by the block' do
You can’t perform that action at this time.
0 commit comments