v1.2.0
cancelation_token
このパッケージはキャンセルトークンのインターフェースとさまざまな実装(キャンセル可能、タイムアウト、複合など)を提供します。
2いいね 3.2万30日間ダウンロード160Pub ポイント
AndroidiOSLinuxmacOSWebWindows
キャンセルトークンインターフェース + いくつかの実装
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
This package provides an interface for cancelation tokens as well as various implementations:
CancelableToken which can be canceled programmatically;CompositeToken which is canceled when any or all tokens are canceled;TimeoutToken which is canceled after a timeout period.Cancel a long-running execution after a timeout.
import 'package:cancelation_token/cancelation_token.dart';
void main() async {
final timeout = Duration(seconds: 5);
final errorOnTimeout = CanceledException.withStackTrace('Too long!');
final token = TimeoutToken(timeout, errorOnTimeout);
token.ensureStarted();
try {
await longProcess(token);
} on CanceledException catch (ex, st) {
print(ex.message);
print(ex.stackTrace);
print(st);
}
}
Future<void> longProcess(CancelationToken token) async {
// very long indeed!
while (true) {
token.throwIfCanceled();
await Future.delayed(const Duration(milliseconds: 100));
}
}
用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗