-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
Description
Steps to reproduce
To reproduce the same issue you can refer the code sample given below.
Expected results
It should only cache successful result.
Actual results
It should not cache exception.
This callback is running
We have successfully cancelled future
Error First Exception: Future Cancelled
Error Second Exception: Future Cancelled
Code sample
Code sample
import 'package:async/async.dart';
late AsyncMemoizer<String> temporaryCache;
late CancelableOperation<String> cancelableOperation;
Future<void> main(List<String> arguments) async {
temporaryCache = AsyncMemoizer<String>();
cancelableOperation =
CancelableOperation.fromFuture(_futureToRun(), onCancel: () {
print('We have successfully cancelled future');
});
cancelableOperation.cancel();
await getData().then((value) => print('First')).onError((error, stackTrace) => print('Error First $error'));
cancelableOperation =
CancelableOperation.fromFuture(_futureToRun(), onCancel: () {
print('We have successfully cancelled future');
});
await getData().then((value) => print('Second')).onError((error, stackTrace) => print('Error Second $error'));
}
Future<String> _futureToRun() async {
await Future.delayed(const Duration(seconds: 5));
return Future.value("Temporary Cache");
}
Future<String> getData() async {
return temporaryCache.runOnce(() async {
print('This callback is running');
String? value = await cancelableOperation.valueOrCancellation();
if (value != null) {
return value;
}
throw Exception('Future Cancelled');
});
}