Class SynFlow
In: lib/syn_flow.rb
Parent: Object

Methods

<<   advance   debug_out   destroy   feed   new   try_advance   try_feed  

Classes and Modules

Class SynFlow::Error

Attributes

i  [R] 
state  [R] 

Public Class methods

[Source]

# File lib/syn_flow.rb, line 236
  def self.debug_out
    @@out
  end

[Source]

# File lib/syn_flow.rb, line 175
  def initialize ( factory, initial_state )
    @i = (@@i += 1)
    super()
    @mutex = Mutex.new
    @condition = ConditionVariable.new
    @factory = factory
    @state = initial_state
  end

Public Instance methods

<<( label )

Alias for feed

advance( label )

Alias for feed

[Source]

# File lib/syn_flow.rb, line 229
  def destroy
    @i = @mutex = @condition = @factory = @state = nil
  end

[Source]

# File lib/syn_flow.rb, line 185
  def feed ( label )
    D "#@i: Want read label #{label} (#@state)"
    @mutex.synchronize do
      while not @factory.include?(@state, label)
        begin
          @condition.wait(@mutex)
        rescue ThreadError
          raise Error,
            'Cannot wait for change state because only one thread is running'
        end
      end
      dest = @factory.delta(@state, label)
      D "#@i: Ok change state with label #{label} (#@state -> #{dest})"
      @state = dest
      @condition.broadcast
    end
  end
try_advance( label )

Alias for try_feed

[Source]

# File lib/syn_flow.rb, line 207
  def try_feed ( label )
    D "#@i: Try read label #{label} (#@state)"
    if @mutex.try_lock
      begin
        if @factory.include?(@state, label)
          dest = @factory.delta(@state, label)
          D "#@i: Ok change state with label #{label} (#@state -> #{dest})"
          @state = dest
          @condition.broadcast
          return true
        end
      ensure
        @mutex.unlock
      end
    end
    D "#@i: Ko you cannot change state"
    return false
  end

[Validate]