run method
Run the system.
System dose nothing until run is called.
After run
get called a Disposer
is return to stop system later:
final disposer = counterSystem.run(); // <- run the system
await Future<void>.delayed(const Duration(seconds: 6));
disposer(); // <- stop the system
Optionally, We can provide additional reduce
and effect
when system run:
final dispose = counterSystem.run(
reduce: (state, event) { ... },
effect: (state, oldState, event, dispatch) { ... },
);
It has same behavior as this:
final dispose = counterSystem
.add(
reduce: (state, event) { ... },
effect: (state, oldState, event, dispatch) { ... },
)
.run();
Implementation
Disposer run({
Reduce<State, Event>? reduce,
Effect<State, Event>? effect,
}) {
var isDisposed = false;
final disposer = _run(
reduce: reduce,
effect: effect,
interceptor: null,
);
return Disposer(() {
if (isDisposed) return;
isDisposed = true;
disposer();
});
}