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 ↗