Manager<T> class abstract

An event-driven structure that has the single state of a type T.

State changes are encapsulated and only possible to be changed internally by calling mutateState or by running a Task via run method.

Key features and advantages:

  • Every single attempt to change the state has its id and will be tracked.
  • The manager allows running multiple AsynchronousTasks concurrently and track progress progress of them through on method.
  • It is possible to filter and listen to incoming TaskEvents through on method by a type of a Task or by Task.id.
  • If you run a Task and manager already has a task with the same id - the previous task will be dismissed. So you don't need to worry about unwanted outcomes.
  • An each Task that was completed with TaskSuccessEvent will change the state through mutateState.
  • You can track an every state change by listening to onStateChanged
Implementers

Constructors

Manager(T initialValue)

Properties

eventSnapshotTable Map<String, TaskEvent<T>>
no setter
hashCode int
The hash code for this object.
no setterinherited
isDisposed bool
If dispose was called on the manager
no setter
onUpdated Stream<void>
Emits an event each time on or onStateChanged fires an event.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state → T
Current state of the manager.
no setter

Methods

dispose() → void
Closing all the sinks of manager.
getAsyncReferenceOf({required String taskId}) AsyncTaskCompleterReference<T>?
Gives a reference for the AsynchronousTask tracked by the manager by taskId.
getEventSnapshot({required String taskId}) TaskEvent<T>?
All events coming from onEventCallback are recorded in the _eventSnapshotTable map and can be accessed by this method using taskId.
kill(CancelableAsyncTaskMixin<T> task) Future<void>
killById({required String taskId}) Future<void>
The method kills a task found by taskId and TaskKillEvent will be added to the on stream.
mutateState(T newState) → void
This method changes the _state and adds events to onStateChanged
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
on<S extends Task<T>>({String? taskId, bool withLatest = false}) Stream<TaskEvent<T>>
Emits TaskEvent while tracking the Tasks
onEventCallback(TaskEvent<T> event) → void
onStateChanged({bool withLatest = false}) Stream<T>
Emits an event each time the state is changed in mutateState
recordEventSnapshot(TaskEvent<T> event) → void
Saves the event into _eventSnapshotTable map
run(Task<T> task) → void
  • If the manager runs a SynchronousTask - only TaskSuccessEvent will be added to the on stream.
  • If the manager runs an AsynchronousTask - the events will be added to the on stream depending on following cases:
  • safelyExtractTaskIdFromString(String taskId) String
    Encapsulated method to form the taskId to get a reference of tasks properly
    safelyGetTaskIdFromTask(Task<T> task) String
    Encapsulated method to form the id of Task to get a reference properly
    testAsyncTaskIdPivotGeneratorRaw(String taskId) String
    toString() String
    A string representation of this object.
    inherited
    waitForTaskToBeDone({required String taskId}) Future<void>

    Operators

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