Skip to content

Instantly share code, notes, and snippets.

@Papipo
Last active August 29, 2015 14:03
Show Gist options
  • Save Papipo/0f6f8d47c6a0cecdd2a8 to your computer and use it in GitHub Desktop.
Save Papipo/0f6f8d47c6a0cecdd2a8 to your computer and use it in GitHub Desktop.
require "concurrent/actress"
module EventSourcing
class AggregateManager
include Concurrent::Actress::Context
def initialize
@registry = {}
end
def on_message(message)
instance_of(message[1], message[2]).message(message)
end
private
def instance_of(klass, id)
unless @registry[id] && !@registry[id].terminated?
@registry[id] = klass.spawn!(id)
end
@registry[id]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment