CTManager class abstract

the base class for managing Cancellation Tokens

this can be used either as a singleton by calling CTManager.I

or

for creating a new CTManager.

example:

  • without singleton
    final ctManager = CTManager();
    final result = await ctManager.run(
      token: 'ct1',
      operation: Future.value('done'),
      onCancel: () => print('cancelled'),
    );
    ...
    
  • with singleton
    final result = await CTManager.I.create(
      token: 'ct1',
      operation: Future.value('done'),
      onCancel: () => print('cancelled'),
    ).result;
    ...
    

Constructors

CTManager()
creates a new CTManager which is capable of managing multiple CancellationToken
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

cancel<T extends Object>(T token) → void
cancels the operation held by CancellationToken of token
cancelAll() → void
cancels all registered operations
create<T extends Object, R extends Object?>({required T token, required Future<R> operation, FutureOr<void> onCancel()?}) → CancellationToken<T, R?>
creates a unique CancellationToken which then can be used to either cancel it or get the value
hasTokenOf<T extends Object>(T token) bool
check if an operation with token is still running/existing
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
noTokenOf<T extends Object>(T token) bool
check if an operation with token has completed/been removed
of<T extends Object, R extends Object?>(T token) → CancellationToken<T, R?>?
returns either:
run<T extends Object, R extends Object?>({required T token, required Future<R> operation, FutureOr<void> onCancel()?}) Future<R?>
a shortcut to create which creates a unique CancellationToken and immediately returns the CancellationToken.result
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

I CTManager
returns a singleton CTManager which is capable of managing multiple CancellationToken
no setter