tonarino / actor

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

Let `Actor`s specify their default `Addr` capacities #70

Closed strohel closed 2 years ago

strohel commented 2 years ago

Currently, if a user wants to create an actor with non-default (normal and/or high-priority) inbox capacities, they need to either create their addr first using Addr::with_capacity() or spawn them using system.prepare[_fn]().with_capacity().

However, the actors themselves often have enough information to determine their best (or at least good default) inbox capacities, so let's allow them doing so! This has a potential to noticeably simplify "actor system setup" codebase sections.

Addr already has actor generic type parameter, so it can access static methods and constants defined on it in its constructor.

Implementation-wise this would be about adding either an associated constant to Actor trait to determine default capacity (if Rust allows having defaults for associated constants), or a static method (without &self) to the Actor trait with default implementation. In both cases we likely don't want to add any more mandatory items that Actors need to implement. Change impl Default for Addr to use these method(s)/constant(s).

Another thing left to bikeshed is whether this should be a single constant/method returning Capacity, or 2 separate methods/constants for normal, high-prio capacities returning usize. Notice the DEFAULT_CHANNEL_CAPACITY constant is not currently public.

CC @bschwind @skywhale @PabloMansanet.