xtra icon indicating copy to clipboard operation
xtra copied to clipboard

Experiment with a functional API

Open thomaseizinger opened this issue 3 years ago • 2 comments

This is probably more something to be added in an extension crate, but it would be cool to be able to define actors from closures:

let initial_state = 0u64;
xtra::actor::unbounded(initial_state)
  .handle(|name: String, ctx: &mut Context| async move {
     format!("Hello {name}")
  });

Not sure how nameable the actor type would be (some nested AndHandler<HandlerFn<String, String>, AndHandler<HandlerFn<u64, u64>>> stuff probably) so perhaps one would only be able to access such an actor through MessageChannels?

thomaseizinger avatar Jul 15 '22 12:07 thomaseizinger

Hmm, this could be interesting, but it would probably lead to explosive compile times 😅 The upshot is that it could be done in an extension crate, though.

Restioson avatar Jul 16 '22 18:07 Restioson

Hmm, this could be interesting, but it would probably lead to explosive compile times sweat_smile The upshot is that it could be done in an extension crate, though.

Yeah definitely in an extension crate.

thomaseizinger avatar Jul 16 '22 18:07 thomaseizinger