withTempPathAsync<T> function

Future<T> withTempPathAsync<T>(
  1. FutureOr<T> callback(
    1. String path
    ), {
  2. String? prefix,
  3. String? suffix,
  4. String? parent,
})

Like withTempPath, but deletes the temporary path asynchronously.

Note that even withTempPath can safely be used with an asynchronous callback. This function is only necessary if you need the automatic filesystem operations to be asynchronous.

Implementation

Future<T> withTempPathAsync<T>(FutureOr<T> callback(String path),
    {String? prefix, String? suffix, String? parent}) async {
  var path = _tempPathName(prefix, suffix, parent);
  try {
    return await callback(path);
  } finally {
    try {
      await File(path).delete(recursive: true);
    } on IOException {
      // Ignore cleanup errors. This is probably because the file was never
      // created in the first place.
    }
  }
}