close method
Implementation
Future<void> close(String path) async {
final normalizedPath = _normalizeSyncPath(path);
if (!_connectedDocuments.containsKey(normalizedPath)) {
throw RoomServerException("Not connected to $normalizedPath");
}
final doc = _connectedDocuments[normalizedPath];
doc!.count--;
if (doc.count == 0) {
_connectedDocuments.remove(normalizedPath);
final streamState = _documentStreams.remove(normalizedPath);
late final Future<void> closeFuture;
closeFuture = () async {
if (streamState != null) {
streamState.closeInputStream();
try {
await streamState.wait();
} finally {
DocumentRuntime.instance!.unregisterDocument(doc.ref);
}
} else {
DocumentRuntime.instance!.unregisterDocument(doc.ref);
}
}();
_closingDocuments[normalizedPath] = closeFuture;
try {
await closeFuture;
} finally {
if (identical(_closingDocuments[normalizedPath], closeFuture)) {
_closingDocuments.remove(normalizedPath);
}
}
}
}