close method

  1. @override
Future<void> close()

Closes the file; further operations throw StateError.

Implementation

@override
Future<void> close() {
  if (_closed) return Future<void>.value();
  _closed = true;
  return _serialize(() async {
    final handles = _chunkHandles.values.toList(growable: false);
    _chunkHandles.clear();
    _lru.clear();
    for (final handle in handles) {
      try {
        await handle.client.flush(handle.handle);
      } catch (_) {
        // Best effort: still try to release the lock.
      }
      try {
        await handle.client.closeHandle(handle.handle);
      } catch (_) {
        // The worker may already be gone; nothing else we can do.
      }
    }
    if (_manifestDirty) await _persist();
  });
}