dispose method
Closes the all-events stream and every node of the bus. Safe to call more than once; after dispose the bus throws StateError on use.
Implementation
@override
Future<void> dispose() async {
if (isDisposed) {
return;
}
// fail the pending replies first, then kill the isolate: otherwise a pending await hangs
_completeInitResult(false);
_link.failAllPending('EventBusIsolate is disposed');
await super.dispose();
_receivePort?.close();
_receivePort = null;
_isolate?.kill(priority: Isolate.immediate);
_isolate = null;
}