Skip to content

Instantly share code, notes, and snippets.

@icnahom
Created April 9, 2025 17:51
Show Gist options
  • Save icnahom/10b2caf1d9d5ca40fe0004721b6726f2 to your computer and use it in GitHub Desktop.
Save icnahom/10b2caf1d9d5ca40fe0004721b6726f2 to your computer and use it in GitHub Desktop.
import 'package:async/async.dart';
Future<void> main() async {
final operation = CancelableOperation.fromFuture(parentFuture());
await Future.delayed(Duration(seconds: 2));
await operation.cancel();
print('canceled');
}
parentFuture() async {
await childFuture();
await childFuture();
await childFuture();
await childFuture();
}
childFuture() async {
await Future.delayed(Duration(seconds: 2));
print('executed');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment