1.6 KiB
swarm — Project Guidelines
Actor Model Conventions
-
One sealed hierarchy per actor. Define a
sealed class FooMessagefor commands and asealed class FooResultfor responses. Every concrete variant is afinal class. -
Handler mixin, not extension. Actors implement
Handler<M, A>viawith, never viaextendsorimplements. -
Factory tear-off for construction.
final actor = Actor.create(FooActor.new);Never pass an already-constructed handler instance across isolate boundaries.
-
Skip
init()andclose()when there is nothing to initialise or release. Override them only when the actor holds persistent resources (sockets, database handles, etc.). -
Errors propagate as exceptions. Throw inside
handle(); theactorsruntime wraps isolate errors inRemoteErrorExceptionon the caller side. Result-type error variants are only justified across network/serialisation boundaries.
Code Style
-
Comment only when intent is not obvious. Skip doc comments on self-explanatory members (
final String path,const FileSaved(), etc.). -
Prefer
constconstructors and declarations wherever the linter suggests. -
No
public_member_api_docslint rule. Forced doc comments on every public member produce noise, not signal. -
prefer_final_fields,avoid_print,sort_pub_dependenciesare enabled.
Content Types
- Actors deal in plain Dart types (
String,int,Map, …) or simple value objects. Binary data (Uint8List) warrants a separate actor rather than overloading an existing one.