close method

  1. @override
void close()

Closes the connection. Firestore calls it when the instance terminates.

Implementation

@override
void close() {
  if (_closed != null) {
    return;
  }
  final Future<void> closed = () async {
    try {
      // See SqliteDatabase.close.
      // ignore: deprecated_member_use
      _database.dispose();
      _sqlite3.unregisterVirtualFileSystem(_registeredFileSystem);
      // Finishes the copies to IndexedDB that are still queued.
      await _fileSystem.close();
    } finally {
      await _releaseLock();
    }
  }();
  _closed = closed;
  // Never fails, so that the next open can simply wait for it.
  late final Future<void> pending;
  pending = closed.then<void>((_) {}, onError: (Object _) {}).whenComplete(
    () {
      if (identical(_closing[path], pending)) {
        _closing.remove(path);
      }
    },
  );
  _closing[path] = pending;
}