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.
- Inheritance
-
- Object
- EventBusImpl
- EventBusIsolate
Constructors
-
EventBusIsolate({required FutureOr<
void> onInit(EventBus isolateBu, Object? initialData), Object? initialData, @Deprecated('Use initialData') Object? initalData})
Properties
-
allEventStream
→ Stream<
(EventDTO, bool)> -
Stream for all sent events (event DTO, and whether it had a listener or not)
no setterinherited
- handlers → EventBusHandlers
-
Handler management without casting
bus as EventBusHandlers.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
-
onInit
→ FutureOr<
void> Function(EventBus isolateBu, 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 - runtimeType → Type
-
A representation of the runtime type of the object.
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
-
addAllHandlerFromOtherBus(
EventBus fromBus) → void -
Adds all handlers from another EventBus to this one.
Nodes are copied: buses don't share state, disposing one doesn't affect the other.
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
-
haveHandler<
T> ({String? path, String? target}) → bool -
Checks if the bus contains a handler for the specified topic.
inherited
-
haveListener<
T> ({String? path, String? target}) → bool -
Checks if the bus contains a listener for the specified topic.
inherited
-
lastData<
T> ({String? path, String? target}) → T? -
Gets the last data sent to a specific topic.
Returns null if no data has been sent to that topic.
inherited
-
listen<
T> ({String? path, String? target}) → Stream< T> -
Listens to events on a specific topic.
Creates a new EventNode if one doesn't exist for that topic.
Returns a Stream of the data type T.
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. -
removeAllHandlerPresentInOtherBus(
EventBus otherBus) → void -
Removes all handlers that are present in another EventBus from this one.
inherited
-
removeHandler<
T> ({String? path, String? target}) → void -
Removes a handler from a specific topic.
Disposes of the EventNode if it exists.
inherited
-
removeNode(
Topic topic, EventNode node) → bool -
This method is called every time a listener closes the stream.
The node is removed if it has no listeners, no handler, and this is not a model bus.
inherited
-
send<
T> (T data, {String? path, String? fragment, String? target, Map< String, String> ? arguments}) → Future -
Sends an event to the bus.
If a handler exists for the topic, it will be called.
Returns a Future that completes with the result if EventDTO.completer was called by the handler.
If no handler exists, returns null.
override
-
setHandler<
T> ({T? initialData, T? initalData, String? path, String? target, required Handler< T> handler}) → void -
Sets a handler for a specific topic.
If an EventNode already exists for that topic, it updates the handler.
Otherwise, it creates a new EventNode with the handler and initial data.
inherited
-
subscribe<
T> ({String? path, String? target, void onData(T e)?, Function? onError, void onDone()?, bool? cancelOnError}) → StreamSubscription< T> -
Subscribe to events on a specific topic.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited