Initial commit

This commit is contained in:
admin1
2026-07-14 11:11:36 +08:00
commit 656499cf94
604 changed files with 119518 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import 'dart:async';
class CancelledException implements Exception {
final String? reason;
const CancelledException([this.reason]);
@override
String toString() =>
reason == null ? 'CancelledException' : 'CancelledException: $reason';
}
class CancellationToken {
final Completer<void> _completer = Completer<void>();
String? _reason;
bool get isCancelled => _completer.isCompleted;
String? get reason => _reason;
Future<void> get whenCancelled => _completer.future;
void cancel([String? reason]) {
if (_completer.isCompleted) return;
_reason = reason;
_completer.complete();
}
void throwIfCancelled() {
if (isCancelled) throw CancelledException(_reason);
}
}