Skip to content

Instantly share code, notes, and snippets.

@thinktainer
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinktainer/47101e784c748117de32 to your computer and use it in GitHub Desktop.
Save thinktainer/47101e784c748117de32 to your computer and use it in GitHub Desktop.
an agent that dies
type EventPublisher (eventBus, logger) =
let agent eventBus (logger : ILoggingService) =
new Agent<EventAggregateMessage>(
fun inbox ->
let rec loop () = async {
let! message = inbox.Receive()
match message with
| EventAggregate aggregate ->
try
let playerId = aggregate.PlayerScope.PlayerId.ToString()
logger.logInfo playerId aggregate.CorrelationToken "sending to bus"
let message = AggregateMapper.toMessageContract aggregate
do! publish eventBus message
logger.logInfo playerId aggregate.CorrelationToken "handled message"
with
| _ as e ->
logger.logError e ""
return! loop ()
| Die -> return () }
loop ())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment