EventBusIsolate class
Atention The result of calling the event can be received later than the events called in the event handler on the isolate side
EventBusIsolate it consists of two Event bus, one on the side of the main isolate and the other in the working isolate. They exchange EventDTO and the results of the handlers' work among themselves.
waitInit completes once the worker has run onInit; before that
send/listen/subscribe throw StateError. Replies are correlated by
request id, so concurrent requests of the same type never get swapped.
The bridge is directional: subscriptions on this bus receive events coming from the worker, and fire sends an event to the worker only. A fired event is not delivered to this bus's own listeners; local pub/sub belongs to an ordinary EventBus (inside Layers that is Layer.current).
- Inheritance
-
- Object
- EventBusImpl
- EventBusIsolate
Constructors
-
EventBusIsolate({required FutureOr<
void> onInit(EventBus bus, Object? initialData), Object? initialData, bool isModelBus = false, ObservabilityConfig observability = ObservabilityConfig.disabled}) -
isModelBusapplies to both sides of the bridge: the bus in the main isolate and the bus inside the worker. A model bus keeps the node and the current value of a topic after its last listener cancels.
Properties
-
allEventStream
→ Stream<
(EventDTO, bool)> -
Stream for all sent events (event DTO, and whether it had a listener or not)
no setterinherited
-
errors
→ Stream<
EventBusError> -
Bus failures as data. The stream never carries stream errors.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
true once dispose has been called
no setterinherited
- isInit → bool
-
true after a successful worker initialization
no setter
- isModelBus → bool
-
no setterinherited
- isObservable → bool
-
True when observability is enabled for this bus.
no setterinherited
- metrics → EventBusMetrics
-
The metric collector of this bus. Safe to read when observability is off:
the snapshot is empty in that case.
no setterinherited
- observabilityConfig → ObservabilityConfig
-
Observability switches of this bus; supplied by the concrete bus.
finalinherited
-
onInit
→ FutureOr<
void> Function(EventBus bus, Object? initialData) -
Worker init function. May be async:
waitInitwaits for it to finish. Must be top-level/static - closures cannot be sent to another isolate.final -
recentErrors
→ List<
EventBusError> -
The latest errors, bounded (100 entries).
no setterinherited
- requestQueueCapacity ↔ int
-
Default requestQueueCapacity for handler subscriptions created without an
explicit override.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- suppressedErrors → int
-
Errors suppressed by the per-kind/topic rate limit.
no setterinherited
-
waitInit
→ Future<
bool> -
Completes with true once the worker has run
onInit, or with an error when the isolate could not be spawned or onInit threw.no setter
Methods
-
createNode<
T> ({required String address, T? currentData}) → EventNode< T> -
Creates the node for an address.
inherited
-
createNodeForKey<
T> ({required EventKey< T> key, T? currentData}) → EventNode<T> -
Creates the node for an exact E key.
inherited
-
createPatternNodeForKey<
T> ({required EventPatternKey< T> key, T? currentData}) → EventNode<T> -
Creates the node for a typed pattern key.
inherited
-
currentData<
T> (EventSelector< T> selector) → T? -
The value stored for a selector: an exact key or a pattern key.
inherited
-
dispose(
) → Future< void> -
Closes the all-events stream and every node of the bus.
Safe to call more than once; after dispose the bus throws StateError on use.
override
-
fire<
T> (EventKey< T> key, T data, {Map<String, String> ? arguments, String? correlationId}) → bool -
Publishes
dataon an exact typed key.override -
handleIncomingRequest(
EventDTO dto, {CancelToken? cancelToken}) → Future -
Dispatches a request received from another process, for example a
transport. The handler is resolved exactly like a local
request.inherited -
handlerAddressFor(
String address) → String? -
The registered address of the tier that would answer
address, or null when no handler exists.inherited -
haveAvailableHandler<
T> (EventSelector< T> selector) → bool -
Whether a handler for the selector could accept a request now.
inherited
-
haveHandler<
T> (EventSelector< T> selector) → bool -
Whether a selector has a handler, including paused handlers.
inherited
-
haveListener<
T> (EventSelector< T> selector) → bool -
Whether a selector has a listener.
inherited
-
listen<
T> (EventSelector< T> selector) → Stream<T> -
Listens to a typed exact or pattern selector.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ping(
{Duration timeout = const Duration(seconds: 2)}) → Future< bool> -
Liveness check: true if the worker replied within
timeout. Readiness (a finished onInit) is reported by waitInit and isInit. -
remove<
T> (EventSelector< T> selector) → bool -
Removes one type node for an exact or pattern selector.
override
-
removeAddress(
EventAddress address) → bool -
Removes every type node registered at an exact address.
override
-
reportError(
EventBusError error) → void -
Publishes a bus error. Transport and isolate adapters use this seam.
inherited
-
request<
T> (EventKey< T> key, T data, {Map<String, String> ? arguments, Duration? timeout, CancelToken? cancelToken, String? correlationId}) → Future -
Sends a request on an exact typed key and waits for the handler result.
override
-
restart(
) → Future< bool> - Replaces the worker with a fresh one while keeping this bus object.
-
shouldCreateNodeOnSend(
String address) → bool -
Whether
sendshould create a node when the topic has none.inherited -
shouldCreateNodeOnSendKey<
T> (EventKey< T> key) → bool -
Whether a send on an exact E key should create a node.
inherited
-
subscribe<
T> (EventSelector< T> selector, {EventCallback<T> ? onEvent, Handler<T> ? handler, T? initialData, int handlerConcurrency = 1, int? requestQueueCapacity, int? bufferCapacity, BufferOverflow bufferOverflow = BufferOverflow.dropOldest, DeliveryMode deliveryMode = DeliveryMode.async, void onError(Object error, StackTrace? stackTrace)?, void onDone()?, bool cancelOnError = false}) → EventSubscription<T> -
Creates a listener and/or handler subscription for a typed selector.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited