Restioson / xtra

🎭 A tiny actor framework
Mozilla Public License 2.0
320 stars 36 forks source link

See if we can simplify `TickFuture` #189

Closed thomaseizinger closed 1 year ago

thomaseizinger commented 2 years ago

Follow-up from #133.

Currently, xtra::tick does two things:

  1. Fetch the next message from the mailbox
  2. Pass the message to the actor

(1) is already possible outside of xtra::tick by calling Mailbox::next. This is the first code-smell. (2) is a bit more tricky because the Message returned by Mailbox::next is an opaque struct for users, they can't do anything with it other than instantiate a TickFuture.

Part of the reason for that is because MessageEnvelope and BroadcastEnvelope return a tuple of the span + the handler future and TickFuture makes use of that by allowing users to attach to that span.

There may be a simpler / more composable way of expressing this by introducing some API on Message that makes it obsolete for users to "call back" into xtra via xtra::tick.

Restioson commented 2 years ago

Is it not the case that if the user wants to poll another future during the loop of an actor, a single, combined receive-and-tick would prevent this?

thomaseizinger commented 1 year ago

Is it not the case that if the user wants to poll another future during the loop of an actor, a single, combined receive-and-tick would prevent this?

I am not advocating for it to be combined. In fact I want to it to be two seperate actions but they should compose well together without the need for xtra::tick.

Restioson commented 1 year ago

Could you give an example on how an API for this could look?

thomaseizinger commented 1 year ago

I put up a PR here: #194.