.Tell
operation without using something like PostSharp to do IL weaving
IActorRef
implementations
mailbox.Context.Child(name)
to try to get the child from the parent by name. If such actor didn't exist, it will return ActorsRefs.Nobody
as a reference.
DeferAsync
works in combination with PersistAsync
, but it's not necessary for Persist
itself. Also Persist takes callback to be called, when event persist will be confirmed
@Horusiath
I had a code:
var events = CurrentState.Change();
PersistAll(events, e => Publisher.Publish(e));
SaveSnapshot(CurrentState);
And it produce invalid snapshots sometimes - it cannot be restored from persisted events. I assume some of events can be lost.
So I'm looking for a way to save snapshot after all events will be persisted, not just one.
Now switched to
var events = CurrentState.Change();
PersistAll(events, e => Publisher.Publish(e));
var state = CurrentState;
Defer(state, s => SaveSnapshot(s));
PersistAll ( events, e => {
if(Decider.ShouldSave(e))
SaveSnapshot(CurrentState);
});
@Horusiath I'm using approach:
Receive<ICommand>(c => {
var events = Aggregate.ExecuteCommand(c);
PersistAll( events);
});
So state is changed before persist, but inside one command method, I'm rely on one-command-in-time actors behaviour
and for me it makes sequence of:
start execute command (Receive)
mutate state (var events = Aggregate.ExecuteCommand(e))
save events (PersistAll)
atomic - while we are in Receive block, no other command can be processed, when we are saving via PersistAll, no other command can be processed
Receive
method while using persistent actor ;)
OnPersistRejected
method, but this won't cause actor to stop