Sha256: f11307553ee151d91380b512b30184104b49f66389f9ee4f7f3fd994b0f61bbc

Contents?: true

Size: 929 Bytes

Versions: 13

Compression:

Stored size: 929 Bytes

Contents

# encoding: utf-8
require 'state_machine'

module Punchblock
  class CommandNode < RayoNode

    attribute :request_id, String, default: ->(*) { Punchblock.new_request_id }

    def initialize(*args)
      super
      @response = FutureResource.new
    end

    state_machine :state, :initial => :new do
      event :request do
        transition :new => :requested
      end

      event :execute do
        transition :requested => :executing
      end

      event :complete do
        transition :executing => :complete
      end
    end

    def response(timeout = nil)
      @response.resource timeout
    end

    def response=(other)
      return if @response.set_yet?
      @response.resource = other
      execute!
    rescue StateMachine::InvalidTransition => e
      e.message << " for command #{self}"
      raise e
    rescue FutureResource::ResourceAlreadySetException
    end
  end # CommandNode
end # Punchblock

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
punchblock-2.7.5 lib/punchblock/command_node.rb
punchblock-2.7.3 lib/punchblock/command_node.rb
punchblock-2.7.2 lib/punchblock/command_node.rb
punchblock-2.7.1 lib/punchblock/command_node.rb
punchblock-2.7.0 lib/punchblock/command_node.rb
punchblock-2.6.0 lib/punchblock/command_node.rb
punchblock-2.5.3 lib/punchblock/command_node.rb
punchblock-2.5.2 lib/punchblock/command_node.rb
punchblock-2.5.1 lib/punchblock/command_node.rb
punchblock-2.5.0 lib/punchblock/command_node.rb
punchblock-2.4.2 lib/punchblock/command_node.rb
punchblock-2.4.0 lib/punchblock/command_node.rb
punchblock-2.3.1 lib/punchblock/command_node.rb