close method
Releases the layer resources: closes both isolate links and the local bus. Works in any layer and is safe to call twice.
Implementation
Future<void> close() async {
var buses = [top, bottom, current];
top = null;
bottom = null;
Object? firstError;
StackTrace? firstStack;
for (var bus in buses) {
if (bus == null) {
continue;
}
try {
await bus.dispose();
} catch (error, stackTrace) {
firstError ??= error;
firstStack ??= stackTrace;
}
}
if (firstError != null) {
Error.throwWithStackTrace(firstError, firstStack ?? StackTrace.current);
}
}