AsyncPublisherWithParam<Param extends Object?, Log extends CustomLog> class final

An asynchronous publisher that handles logs paired with a specific parameter.

Useful for scenarios where a publisher needs some auxiliary parameter that might change or be specific to a certain context (e.g., different output files or connection endpoints), processing requests sequentially.

Example usage:

final asyncPublisher = AsyncPublisherWithParam<String, Log>((filePath, log) async {
  await File(filePath).writeAsString(log.toString(), mode: FileMode.append);
});

log.publisher = asyncPublisher.withParam('app.log');
Inheritance

Constructors

AsyncPublisherWithParam(FutureOr<void> handler(Param param, Log log), {bool sync = false, void onError(Object error, StackTrace stackTrace)?})
Creates a publisher backed by handler.

Properties

handler FutureOr<void> Function(Param param, Log log)
The function that processes a single log event with its parameter.
final
hashCode int
The hash code for this object.
no setterinherited
isClosed bool
Whether close has been called.
no setterinherited
onError → void Function(Object error, StackTrace stackTrace)?
Called when handle throws.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sync bool
Whether the underlying stream controller delivers events synchronously.
finalinherited

Methods

close() Future<void>
Closes the publisher after processing the already queued log events.
inherited
flush() Future<void>
Completes when every log event queued before this call has been processed.
inherited
handle(Param param, Log log) FutureOr<void>
Processes a single log event with its bound parameter.
override
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 queue with the given param attached to every log event.
inherited

Operators

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