tonarino / actor

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

Simplified Recipient API #42

Closed mcginty closed 3 years ago

mcginty commented 3 years ago

Implements a derivative of the API @strohel proposed in #20. Slightly modified to allow the Recipient to not need to hold actor_name which didn't seem necessary.

My proposed API looks like:

// Error on both disconnect and channel full.
recipient.send(msg)?;

// Error on disconnect only.
recipient.send(msg).ignore_on_full()?;

// Error on disconnect, run closure on full.
recipient.send(msg).on_full(|| warn!("dropped frame: channel full")?;

Which detaches it specifically from the log crate, and allows the user to specify things like the log level.

Fixes #20.

strohel commented 3 years ago

One more thing I've realized about the signature fn on_full<F>(self, func: F) -> Self: This currently allows recipient.send(msg).on_full(foo).on_full(bar), which may sound like both foo and bar should be executed when the channel is full. But bar will be never run under current design.

I've originally envisioned that fn_full() & friends would return some different Result<(), DisconnectedError>, preventing this. But perhaps that is kinda too elaborate? No strong opinion. BTW, if some DisconnectedError is introduced, Recipient::stop() could use it, too.

mcginty commented 3 years ago

@strohel That's a good point, if only just because the full error is impossible after passing it through that function :). I'll make that change.