hegemon 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hegemon.rb +20 -9
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b434952e8994ae0a8d76f3892f7519a3ef21fbd
4
- data.tar.gz: dfcfaf716ddaefe24334316dbc03597bdb42150f
3
+ metadata.gz: a167a9bc4711dc205fcebe150e328cbda3c0df16
4
+ data.tar.gz: 5f24fa3dfe4dd37a911d37d05e82e1bc26535d0c
5
5
  SHA512:
6
- metadata.gz: dd1b9994151efd8aa79065d1f3cf96753661d17d57ee317ec2deb5d948cce280013996f1516eefca9353d0c082de73aca8417d683315f83ae879242849098d70
7
- data.tar.gz: 138a26699c3523e855e554bb71f555f9154d8d11d66c086586cd19ec3208e1d7169a6f61ef43126df41476ffce105f15fa7cd1a3520cb064478eab3a407a7dcc
6
+ metadata.gz: 878c9a6e4b66597806d9cdc4943a178542eccd0c4e93a2f12ccfd9f03263e81039096515ec2e7d081e1c0bed5b6116b4868a6b079c8a01338dd74b8384e753db
7
+ data.tar.gz: 1212f88744fa2bafce52df032008a1ffa0f9cc8ff6075ec06fe6dd33679d8e203566168aa0d253d1442217b2523f09d5d768136e51a3a65ea76403cc57de310a
@@ -182,10 +182,14 @@ module Hegemon
182
182
  # [+state+]
183
183
  # The symbol to compare against the current state against
184
184
  #
185
+
185
186
  def block_until_state(s); # :args: state
186
187
  raise ArgumentError, "Cannot block until undefined state :#{s}" \
187
188
  unless @_hegemon_states.keys.include? s
188
- sleep 0 until @_hegemon_state==s
189
+
190
+ @_hegemon_transition_lock ||= Monitor.new
191
+ sleep 0 until @_hegemon_transition_lock.synchronize { @_hegemon_state==s }
192
+
189
193
  nil end
190
194
 
191
195
  #
@@ -233,7 +237,7 @@ module Hegemon
233
237
  or (not @_hegemon_auto_thread.status)
234
238
 
235
239
  @_end_hegemon_auto_thread = false
236
- @_hegemon_auto_thread_throttle ||= throttle
240
+ @_hegemon_auto_thread_throttle = throttle
237
241
  @_hegemon_auto_thread = Thread.new do
238
242
  i = 0
239
243
  until @_end_hegemon_auto_thread
@@ -315,6 +319,11 @@ class HegemonTransition
315
319
  @src_state = src_state
316
320
  @dest_state = dest_state
317
321
 
322
+ @object.instance_variable_set(:@_hegemon_transition_lock,
323
+ (@transition_lock = Monitor.new)) \
324
+ unless (@transition_lock = @object.instance_variable_get( \
325
+ :@_hegemon_transition_lock))
326
+
318
327
  @conditions = []
319
328
  @sufficients = []
320
329
  @requirements = []
@@ -359,13 +368,15 @@ class HegemonTransition
359
368
  private
360
369
 
361
370
  def perform
362
- @progress = :pre
363
- procs_run(@befores)
364
- @progress = :impose
365
- @object.impose_state(@dest_state)
366
- @progress = :post
367
- procs_run(@afters)
368
- @progress = nil
371
+ @transition_lock.synchronize do
372
+ @progress = :pre
373
+ procs_run(@befores)
374
+ @progress = :impose
375
+ @object.impose_state(@dest_state)
376
+ @progress = :post
377
+ procs_run(@afters)
378
+ @progress = nil
379
+ end
369
380
  nil end
370
381
 
371
382
  def procs_run(list)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hegemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe McIlvain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-07 00:00:00.000000000 Z
11
+ date: 2013-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: threadlock