パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.2.0

cancelation_token

このパッケージはキャンセルトークンのインターフェースとさまざまな実装(キャンセル可能、タイムアウト、複合など)を提供します。

AndroidiOSLinuxmacOSWebWindows
30日間ダウンロード
3.2万
いいね数
2
Pub ポイント
160

パッケージをインストール

flutter pub add cancelation_token

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

The cancelation_token package offers a clean interface for managing cancellation in asynchronous operations, supporting various implementations like cancelable tasks, timeouts, and composite tokens. It enables developers to gracefully handle operation cancellation across platforms, improving responsiveness and resource management in Flutter apps. Ideal for scenarios involving network requests, timers, or long-running computations that may need to be interrupted. The package is lightweight and designed for use with Dart's async/await patterns.

用途

  • Managing cancellable network requests
  • Implementing timeout mechanisms
  • Coordinating multiple async operations
  • Handling user-initiated task cancellation
  • Controlling long-running background processes

主な機能

  • Support for cancelable futures
  • Timeout-based cancellation
  • Composite token grouping
  • Cross-platform compatibility
  • Simple API integration

適している対象

  • Developers needing fine-grained control over async operations
  • Apps with frequent network or timer usage
  • State management systems requiring cancellation support
  • Teams prioritizing clean async code structure

注意事項

  • Requires understanding of async/await flow
  • May add complexity for simple use cases
  • Not suitable for non-async operations
  • Limited documentation beyond basic examples
  • Best used with other state management solutions

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

cancelation_token

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.

Example

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));
  }
}

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。

ランキング