Sha256: 11c3ff3aa242a1ddbedb22dbfd594bffb82db6ca46e24d65e30dff994adb1485
Contents?: true
Size: 1.25 KB
Versions: 9
Compression:
Stored size: 1.25 KB
Contents
require 'celluloid' module Nestene module Actor class AutonStorage include Celluloid include Celluloid::Notifications exclusive :create, :get, :update execute_block_on_receiver :update def initialize(auton_id, storage) @auton_id = auton_id @storage = storage state = get publish('state_update', @auton_id, state) if state end def create type state = AutonState.new state.type = type instance = Nestene::class_from_string(type).new state.serialized = instance.to_structure @storage.store(@auton_id,state.to_structure) publish('state_update', @auton_id, state) rescue Exception => e abort e end def get structure = @storage.load(@auton_id) structure ? AutonState.from_structure(structure) : nil end def update &block before = @storage.load(@auton_id) state = AutonState.from_structure(@storage.load(@auton_id)) result = block.call(state) after = state.to_structure @storage.store(@auton_id,after) publish('state_update', @auton_id, state) if before != after result rescue Exception => e abort e end end end end
Version data entries
9 entries across 9 versions & 1 rubygems