writeAsBytesLimited method

Future<File> writeAsBytesLimited(
  1. List<int> bytes, {
  2. FileMode mode = FileMode.write,
  3. bool flush = false,
})

Similar to File.writeAsBytes, but limits concurrency to a maximum of _semaphoreLimit simultaneous writes.

This prevents excessive concurrent file access that could cause I/O bottlenecks or file handle exhaustion.

Implementation

Future<File> writeAsBytesLimited(
  List<int> bytes, {
  FileMode mode = FileMode.write,
  bool flush = false,
}) async {
  await _semaphore.acquire();
  try {
    return await writeAsBytes(bytes, mode: mode, flush: flush);
  } finally {
    _semaphore.release();
  }
}