withTempPathAsync<T> function
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.
}
}
}