Sha256: 62a2d55f3cdfda55b80d1275d4a94d6c4930772ccb2f5fdff4399a96f7c5d39a
Contents?: true
Size: 730 Bytes
Versions: 36
Compression:
Stored size: 730 Bytes
Contents
require 'delegate' require 'thread' # Controls the state of the Worker object, and wraps it's state transitions # with a Mutex. class Sqewer::StateLock < SimpleDelegator def initialize @m = Mutex.new m = VeryTinyStateMachine.new(:stopped) m.permit_state :starting, :running, :stopping, :stopped, :failed m.permit_transition :stopped => :starting, :starting => :running m.permit_transition :running => :stopping, :stopping => :stopped m.permit_transition :starting => :failed # Failed to start __setobj__(m) end def in_state?(some_state) @m.synchronize { __getobj__.in_state?(some_state) } end def transition!(to_state) @m.synchronize { __getobj__.transition!(to_state) } end end
Version data entries
36 entries across 36 versions & 1 rubygems