Cooperative cancellation with one-shot listeners; throwIfCancelled throws StateError after cancellation.
| Member / type / return | Meaning |
|---|---|
bool isCancelled = false | Whether cancellation has been requested. |
void cancel() | Set synchronously to true to cancel the action. |
VoidCallback onCancel(VoidCallback listener) | Registers a cancellation listener; called immediately if already cancelled. The return value unregisters it. |
void throwIfCancelled() | Throws StateError if the token was cancelled. |
import 'package:flutter/material.dart';
import 'package:tecexpress/tecexpress.dart';
Future<void> example() async {
final token = TxCancellation();
final unregister = token.onCancel(() => debugPrint('Cancelled'));
token.throwIfCancelled();
token.cancel();
unregister();
}