```
try {
  writeFn(writer)
  writer.flush()
} finally {
  writer.close()
}
```