StatefulService<S> class abstract

A base class for representing a stateful service.

The service state is available through the values value stream but the only way to update it is by returning/ yielding new values from the provided callbacks. This allows us to serialize all state changes and reduce the risk of race conditions.

Implementers

Constructors

StatefulService.new({required S initialState, String? name, Logger? logger, FutureOr<S> init(S)?, StatefulServiceCache<S>? cache, bool cacheValidator(S)?, bool shouldStateBeEmitted(S previousState, S newState)?, bool verboseLogging = false})
Creates a new StatefulService with the provided initialState.

Properties

hashCode int
The hash code for this object.
no setterinherited
initComplete Future<S>
A Future that completes when the service has finished initializing. It will contain the state's first emitted state.
latefinal
isClosed bool
Returns true if this service has been closed. If this returns true, all calls to update the service's state will fail.
no setter
isInitializing bool
no setter
isUpdating bool
Returns true if this service is currently processing an update call.
no setter
name String
The provided name of this service, or the runtime type if none was provided.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state ServiceState<S>
The service's current state.
no setter
states Stream<ServiceState<S>>
This stream emits the service's state whenever it changes, it will never emit errors.
no setter
values Stream<S>
This stream emits the service's state whenever it changes, it will never emit errors.
no setter
verboseLogging bool
final

Methods

clearCache() Future<void>
Clears this service's state cache. Note that this will not affect the current state of the service.
close() Future<void>
Closes the service. Any in-flight update operations will be discarded and further calls to update the service state will result in errors.
listen(void onData(ServiceState<S> value)) StreamSubscription<ServiceState<S>>
Listens to the state stream and calls onData whenever a new state is emitted.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
set(S value, {bool ignoreConcurrentUpdates = false}) Future<void>
Sets the service's state to the provided value directly, without needing changing the service into an intermediate loading state.
streamUpdates(Stream<S> updates(S state, S setSavePoint(S)), {bool ignoreConcurrentUpdates = false}) Future<void>
Performs a series of updates of service's state with the values emitted from the stream returned by updates. The service state will be locked (no other updates can take place) until the stream completes. update receives two arguments; the service's current state, and a function to call to save the current state as a savepoint.
toString() String
A string representation of this object.
inherited
update(FutureOr<S> update(S state), {bool ignoreConcurrentUpdates = false}) Future<void>
Makes a single update to this service's state with the value returned from update.

Operators

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