Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AK1000: warn users about using ReceiveAsync when not actually doing any await-ing #57

Closed
Aaronontheweb opened this issue Jan 17, 2024 · 0 comments · Fixed by #61
Closed
Labels
AK1000 Actor design rules.

Comments

@Aaronontheweb
Copy link
Member

Is your feature request related to a problem? Please describe.

From the submission on #55

public sealed class MyActor : ReceiveActor{
   public MyActor(){
      ReceiveAsync<string>(str => Sender.Tell(str)); // should get a warning here
   }
}

Using ReceiveAsync this way is less performant than a normal Receive because this generates an extra ActorTask message plus an additional suspend + resume of the actor's mailbox. That overhead is fine if you're await-ing something, but if the code is essentially synchronous then we should not do so.

Describe the solution you'd like

Issue a WARNING level severity here and a code fix to rewrite the ReceiveAsync to a regular Receive if the ReceiveAsync doesn't actually have any awaits happening inside of it.

Additional context

If the user is invoking a declared method as the ReceiveAsync handler instead of an anonymous delegate, that might be a lot trickier to analyze correctly as the method can get used across multiple callsites. Maybe it's best to skip doing that for now.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
AK1000 Actor design rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant