Closeable constructor

Closeable()

An object that may hold resources until it is closed.

The close method is invoked to release resources that the object is holding (such as open files). The close method is idempotent - calling it multiple times should have no additional effect.

Example Usage

class FileResource implements Closeable {
  final File _file;
  bool _closed = false;
  
  FileResource(String path) : _file = File(path);
  
  @override
  Future<void> close() async {
    if (_closed) return;
    _closed = true;
    // Perform cleanup
  }
}

// Usage with try-finally
final resource = FileResource('data.txt');
try {
  // Use resource
} finally {
  await resource.close();
}

Implementation

Closeable();