AsyncPublisherWithBufferAndParamBase<Param extends Object?, Log extends CustomLog> class
abstract
base
A base class for asynchronous publishers that buffer logs alongside contextual parameters, emitting batches of parameter-log pairs.
This bridges the batched workflow of buffer-based publishers with the contextual routing of parameter-based publishers.
Example usage:
final class MetricsPublisher extends AsyncPublisherWithBufferAndParamBase<String, Log> {
@override
Future<void> handle(
List<(String, Log)> entries,
List<(String, Log)> retryBuffer,
) async {
try {
await metricsClient.sendBatch(entries); // entries are a list of (String source, Log log)
} catch (e) {
retryBuffer.addAll(entries); // Queue failed logs back for next flush
}
}
}
log.publisher = asyncPublisher.withParam(source);
Constructors
- AsyncPublisherWithBufferAndParamBase({bool sync = false, void onError(Object error, StackTrace stackTrace)?})
- Creates the publisher and its buffered processing queue.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClosed → bool
-
Whether close has been called.
no setter
- onError → void Function(Object error, StackTrace stackTrace)?
-
Called when handle throws.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sync → bool
-
Whether the underlying stream controller delivers events synchronously.
final
Methods
-
close(
) → Future< void> -
Closes the publisher after draining the queue: every log accepted
before closing is processed, including logs published while a batch
was in flight. Entries returned to the retry buffer after closing are
dropped.
override
-
flush(
) → Future< void> -
Completes when the queue has been fully drained.
override
-
handle(
List< (Param, Log)> entries, List<(Param, Log)> retryBuffer) → FutureOr<void> -
Processes a batch of buffered parameter-log
entries. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
withParam(
Param param) → CustomLogPublisher< Log> -
Returns a CustomLogPublisher that publishes into this shared buffer
with the given
paramattached to every log event.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited