writeAsBytesLimited method
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();
}
}