Sha256: 5d0eea75a6603d33a65c148705229a25515b444e3386405435c7db0f9e9666b7

Contents?: true

Size: 711 Bytes

Versions: 2

Compression:

Stored size: 711 Bytes

Contents

module Pione
  module Agent
    # TrivialRoutineWorker represents agent class for doing action periodly.
    class TrivialRoutineWorker < BasicAgent
      # state
      define_state :working

      # transition table
      define_state_transition :initialized => :working
      define_state_transition :working => :working

      # Creates a worker.
      # @param [Proc] action
      #   worker's action as proc object
      # @param [Integer] sec
      #   sleeping time
      def initialize(action)
        raise ArgumentError.new(action) unless action.kind_of?(Proc)
        @action = action
      end

      # Calls the action.
      def transit_to_working
        @action.call
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pione-0.1.1 lib/pione/agent/trivial-routine-worker.rb
pione-0.1.0 lib/pione/agent/trivial-routine-worker.rb