pantomime-rs / pantomime

MIT License
5 stars 1 forks source link

Actor Result support #31

Open longshorej opened 5 years ago

longshorej commented 5 years ago

I'm unsure whether such a feature is necessary, but filing the issue to gather thoughts.

Should we have some sugar to support that use-case? Without any explicit feature, the user might employ a pattern like this:

struct MyMsg;

struct MyActor;

impl MyActor {
  fn handle(msg: MyMsg, ctx: &mut ActorContext) -> Result<()> {
    let thing = some_possible_failure(msg)?;
    let other_thing = some_other_thing(&thing);

    Ok(())
  }
}

impl Actor<MyMsg> for MyActor {
  fn receive(&mut self, msg: MyMsg, ctx: &mut ActorContext) {
    match self.handle(msg, ctx) {
      Ok(()) => {}

      Err(e) => {
        ctx.fail(e);
      }
  }

It feels like that would get repetitive quick, but maybe it's fine.