-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CommandAsync for persistent actors #2689
Conversation
|
||
namespace Akka.Persistence.Tests | ||
{ | ||
//internal class BehaviorOneActor : PersistentActorSpec.ExamplePersistentActor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this part commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to move it to another namespace. It inherits from PersistentActorSpec.ExamplePersistentActor but i need to use a different actor with the RunTask inside
@@ -243,6 +243,7 @@ namespace Akka.Persistence | |||
public void PersistAsync<TEvent>(TEvent @event, System.Action<TEvent> handler) { } | |||
protected abstract bool ReceiveCommand(object message); | |||
protected abstract bool ReceiveRecover(object message); | |||
protected void RunTask(System.Func<System.Threading.Tasks.Task> action) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is not unique for the persistence. It should be either hidden or included in ActorBase
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it is unique to Eventsourced, because of the Persist callbacks.
Non-persistence actors already have other equivalents, e.g. UntypedActor have RunTask, ReceiveActor have ReceiveAsync
if (!t.IsCompleted) | ||
{ | ||
var tcs = new TaskCompletionSource<object>(); | ||
t.ContinueWith(r => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably won't need TaskCompletionSource
here. ContinueWith
will return continuation task, while TaskContinuationOption.NotOnFaulted | TaskContinuationOption.NotOnCancelled
should allow you to get rid of forwarding cancelations and faults.
There's also one thing to remember - things like actor's Context
or Self
are fragile and won't work in task continuations. This also concerns all methods invoked here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I didn't need it, but now i need to react also on failure.
Regarding Context, it works as usual. Context, Sender,.. are accessible inside the command handler. Same for Persist callback except of the Sender, but that's by design
Persist(new Evt(cmd.Data + "-0"), UpdateStateHandler); | ||
Context.Become(NewBehavior); | ||
}); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's fully valid way of calling RunTask. As it won't be invoked immediately, the handler will return true, while the func inside may throw an exception. This may lead to a false positives, but I'd need to check how this would look like in other cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be the same behavior as with ReceiveAsync
Need to run the API approval process locally... http://getakka.net/docs/akka-developers/public-api-changes |
@Aaronontheweb will do that. Btw there is an issue with the approval ApiGenerator, the order of items is based on local culture, InvariantCulture might be better. Will create another pull request for that |
@zbynek001 rebasing on those changes since we merge in your API approval fix. |
Has some minor conflicts that need to be resolved. @Aaronontheweb we are not making this part of release 1.3 ? |
@Danthar yeah, this should definitely go into 1.3 |
Here is another try on CommandAsync topic.
I's introducing similar support for async/await as in ReceiveAsync.
Remarks: