패키지, 저장소 및 앱 카테고리 검색

패키지 상세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));
  }
}

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.

순위