stop method
Stops the container: deactivates every feature (LIFO), runs per-feature lifetime cleanup, disposes the per-cycle stores and status stores, clears port handlers, and drops every registered event listener. The container then returns to ContainerStatus.idle and start can be called again to spin up a fresh cycle (with new store instances).
No-op when already .idle. Concurrent calls coalesce into the
same in-flight future.
Cannot be called from a feature lifecycle callback (setup,
onStart, port handlers) — throws ContainerUsageError. Schedule
the stop outside the callback if you need to.
References to stores / exports / handler context obtained from
the previous cycle are stale after stop. The underlying objects
were disposed; re-fetch through use(...) / useStore(...) after
the next start. Widget consumers using WatchPort /
useFeature re-resolve through the container on rebuild.
Event listeners registered via onFeatureStatusChanged / onPortChanged are dropped. Re-subscribe after the next start if you want to keep observing.
Per-cycle resources (a websocket, a database handle, a telemetry
session) belong inside a feature's setup / onStart and its
cleanup bag — not at the container level. The cleanup bag
drains automatically on stop, then a fresh one is allocated for
the next cycle.
Implementation
Future<void> stop() {
return _stopping ??= _runStop();
}