tonarino / actor

A minimalist actor framework aiming for high performance and simplicity.
MIT License
40 stars 6 forks source link

Return the message in an error if it failed to be sent #75

Open bschwind opened 1 year ago

bschwind commented 1 year ago

Flume has a TrySendError which returns the message that we attempted to send.

We should surface this to our API so actors can decide what to do with the message if it failed to send.

This might create an explosion of generics so let's approach this carefully.

strohel commented 1 year ago

Yeah this may end up being a bit tricky in current type design of actor:

We allow infinite Recipient<T> -> Recipient<U> -> Recipient<V> conversions provided the messages can be converted (V -> U -> T). But we don't want to add the bound in the other direction (T -> U), as that might not be possible for user to fullfil at all.

So our Recipient<V> cannot return SomeError<V>, and it also cannot return SomeError<T>, because the whole point of Recipient is to erase the T generic parameter.

It could return Box<dyn Any>, but that would incur the boxing costs on all failures to send (some users may send large volume of big messages that are largely dropped, and don't care about it).

Maybe there is some other way, perhaps registering some form or callback etc.