cztop-reactor 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebc72ede3239718ff03c2c29509a494c993d2d115bf07b4c3d5d748ea4f20ae6
4
- data.tar.gz: 77596ee72fc148492039318ee36ba075152b96a963421d458c88df884b0d267f
3
+ metadata.gz: 17bf40bedf4749f22ba30e33ea82296f2936267c4fcefc3c01d2e795ad7d741c
4
+ data.tar.gz: 00063eb4d49d06906fa50e778447816503302b42e8551cc6cb3ccae7b7422e70
5
5
  SHA512:
6
- metadata.gz: 0b2bf31a6cf841f39395dc04aa25ca80a0dbbbeddc267393410f77e072671c817c4e4d82dd0429e9869c1bf67c7f7f0dc91ab121cc2f66d5614727c6c56645fc
7
- data.tar.gz: 470fca566a0285487be7ad4dbe6b3bdb40a8c61cb64c01b11d28b86e70bed17da5052efad30185216c9273a7fcc0afcaed4cfeb62aba99c67c164cbfcdb4cc6b
6
+ metadata.gz: fdab82704df0e87ac9b742fff14d72dc3c9d0b48d7d9fc5af76160a662ff8fa3b4ec5d3567246ba4c9ea7b0e8c56cf0fde171d2542d8a91f539774f12eb21500
7
+ data.tar.gz: 202f8a04ccb8bc02653eca063777b1c949fdb6bfe27561c94ed2205af5b4fea1b6d28e27948092ad24eff8c09af4ab143ae8264ba09626b2719eb42de9732538
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## v0.5.0 [2018-07-11] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Enhancements:
4
+
5
+ - Added methods to pause/resume all timers.
6
+
7
+
1
8
  ## v0.4.0 [2018-06-27] Michael Granger <ged@FaerieMUD.org>
2
9
 
3
10
  Enhancements:
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ hoespec = Hoe.spec 'cztop-reactor' do |spec|
31
31
  spec.developer 'Michael Granger', 'ged@FaerieMUD.org'
32
32
 
33
33
  spec.dependency 'loggability', '~> 0.14'
34
- spec.dependency 'cztop', '~> 0.11'
34
+ spec.dependency 'cztop', '~> 0.13'
35
35
  spec.dependency 'timers', '~> 4.1'
36
36
 
37
37
  spec.dependency 'hoe-deveiate', '~> 0.9', :developer
data/lib/cztop/reactor.rb CHANGED
@@ -24,7 +24,7 @@ class CZTop::Reactor
24
24
  include MonitorMixin
25
25
 
26
26
  # The version of this library
27
- VERSION = '0.4.0'
27
+ VERSION = '0.5.0'
28
28
 
29
29
  # The maximum number of seconds to wait for events when there are no timers
30
30
  # registered.
@@ -251,6 +251,28 @@ class CZTop::Reactor
251
251
  end
252
252
 
253
253
 
254
+ ### Pause all timers registered with the reactor.
255
+ def pause_timers
256
+ self.timers.pause
257
+ end
258
+
259
+
260
+ ### Resume all timers registered with the reactor.
261
+ def resume_timers
262
+ self.timers.resume
263
+ end
264
+
265
+
266
+ ### Execute a +block+ with all registered timers paused, then resume them when
267
+ ### the block returns.
268
+ def with_timers_paused
269
+ self.pause_timers
270
+ return yield
271
+ ensure
272
+ self.resume_timers
273
+ end
274
+
275
+
254
276
  #
255
277
  # Monitors
256
278
  #
@@ -212,6 +212,63 @@ describe CZTop::Reactor do
212
212
  expect( reactor.timers ).to include( handle )
213
213
  end
214
214
 
215
+
216
+ it "allows all timers to be paused" do
217
+ timer1 = reactor.add_periodic_timer( 5 ) {}
218
+ timer2 = reactor.add_periodic_timer( 15 ) {}
219
+ timer3 = reactor.add_periodic_timer( 115 ) {}
220
+ timers = [ timer1, timer2, timer3 ]
221
+
222
+ reactor.pause_timers
223
+
224
+ expect( timers ).to all( be_paused )
225
+ end
226
+
227
+
228
+ it "allows all timers to be resumed" do
229
+ timer1 = reactor.add_periodic_timer( 5 ) {}
230
+ timer2 = reactor.add_periodic_timer( 15 ) {}
231
+ timer3 = reactor.add_periodic_timer( 115 ) {}
232
+ timers = [ timer1, timer2, timer3 ]
233
+
234
+ reactor.pause_timers
235
+ reactor.resume_timers
236
+
237
+ expect( timers.none?(&:paused?) ).to be_truthy
238
+ end
239
+
240
+
241
+ it "allows a block to be run while timers are paused" do
242
+ timer1 = reactor.add_periodic_timer( 5 ) {}
243
+ timer2 = reactor.add_periodic_timer( 15 ) {}
244
+ timer3 = reactor.add_periodic_timer( 115 ) {}
245
+ timers = [ timer1, timer2, timer3 ]
246
+
247
+ result = reactor.with_timers_paused do
248
+ expect( timers ).to all( be_paused )
249
+ :the_blocks_result
250
+ end
251
+
252
+ expect( result ).to eq( :the_blocks_result )
253
+ expect( timers.none?(&:paused?) ).to be_truthy
254
+ end
255
+
256
+
257
+ it "resumes timers even if the paused-timer block errors" do
258
+ timer1 = reactor.add_periodic_timer( 5 ) {}
259
+ timer2 = reactor.add_periodic_timer( 15 ) {}
260
+ timer3 = reactor.add_periodic_timer( 115 ) {}
261
+ timers = [ timer1, timer2, timer3 ]
262
+
263
+ expect {
264
+ reactor.with_timers_paused do
265
+ raise "something bad"
266
+ end
267
+ }.to raise_error( 'something bad' )
268
+
269
+ expect( timers.none?(&:paused?) ).to be_truthy
270
+ end
271
+
215
272
  end
216
273
 
217
274
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cztop-reactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -35,7 +35,7 @@ cert_chain:
35
35
  X0qdrKi+2aZZ0NGuFj9AItBsVmAvkBGIpX4TEKQp5haEbPpmaqO5nIIhV26PXmyT
36
36
  OMKv6pWsoS81vw5KAGBmfX8nht/Py90DQrbRvakATGI=
37
37
  -----END CERTIFICATE-----
38
- date: 2018-06-27 00:00:00.000000000 Z
38
+ date: 2018-07-11 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: loggability
@@ -57,14 +57,14 @@ dependencies:
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0.11'
60
+ version: '0.13'
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.11'
67
+ version: '0.13'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: timers
70
70
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file