close method
Close the sink and ensure all pending trace data is flushed to the target.
Implementation
@override
Future<void> close() async {
if (_closing) return;
_closing = true;
if (!_initialized && !_failed) {
await _initCompleter.future;
}
_closed = true;
final port = _serializerPort;
final isolate = _serializerIsolate;
if (_failed || port == null || isolate == null) {
isolate?.kill();
return;
}
final replyPort = ReceivePort();
final onExitPort = ReceivePort();
final done = Completer<void>();
void finish([Object? _]) {
if (!done.isCompleted) done.complete();
}
replyPort.listen(finish);
onExitPort.listen(finish);
isolate.addOnExitListener(onExitPort.sendPort);
port.send(_TerminateSignal(replyPort.sendPort));
try {
await done.future;
} finally {
replyPort.close();
onExitPort.close();
isolate.kill();
}
}