MultiStreamController<T> abstract interface#
An enhanced stream controller provided by Stream.multi.
Acts like a normal asynchronous controller, but also allows adding events synchronously. As with any synchronous event delivery, the sender should be very careful to not deliver events at times when a new listener might not be ready to receive them. That usually means only delivering events synchronously in response to other asynchronous events, because that is a time when an asynchronous event could happen.
Implemented types
Properties#
done no setter inherited#
A future which is completed when the stream controller is done sending events.
This happens either when the done event has been sent, or if the subscriber on a single-subscription stream is canceled.
A stream controller will not complete the returned future until all listeners present when the done event is sent have stopped listening. A listener will stop listening if it is cancelled, or if it has handled the done event. A paused listener will not process the done even until it is resumed, so completion of the returned Future will be delayed until all paused listeners have been resumed or cancelled.
If there is no listener on a non-broadcast stream, or the listener pauses and never resumes, the done event will not be sent and this future will never complete.
Inherited from StreamController.
Implementation
Future get done;
hashCode no setter inherited#
The hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Object.
Implementation
external int get hashCode;
hasListener no setter inherited#
Whether there is a subscriber on the Stream.
Inherited from StreamController.
Implementation
bool get hasListener;
isClosed no setter inherited#
Whether the stream controller is closed for adding more events.
The controller becomes closed by calling the close method. New events cannot be added, by calling add or addError, to a closed controller.
If the controller is closed, the "done" event might not have been delivered yet, but it has been scheduled, and it is too late to add more events.
Inherited from StreamController.
Implementation
bool get isClosed;
isPaused no setter inherited#
Whether the subscription would need to buffer events.
This is the case if the controller's stream has a listener and it is paused, or if it has not received a listener yet. In that case, the controller is considered paused as well.
A broadcast stream controller is never considered paused. It always forwards its events to all uncanceled subscriptions, if any, and let the subscriptions handle their own pausing and buffering.
Inherited from StreamController.
Implementation
bool get isPaused;
onCancel read / write inherited#
getter:
The callback which is called when the stream is canceled.
May be set to null, in which case no callback will happen.
setter:
The callback which is called when the stream is canceled.
May be set to null, in which case no callback will happen.
Inherited from StreamController.
Implementation
abstract FutureOr<void> Function()? onCancel;
onListen read / write inherited#
getter:
The callback which is called when the stream is listened to.
May be set to null, in which case no callback will happen.
setter:
The callback which is called when the stream is listened to.
May be set to null, in which case no callback will happen.
Inherited from StreamController.
Implementation
abstract void Function()? onListen;
onPause read / write inherited#
getter:
The callback which is called when the stream is paused.
May be set to null, in which case no callback will happen.
Pause related callbacks are not supported on broadcast stream controllers.
setter:
The callback which is called when the stream is paused.
May be set to null, in which case no callback will happen.
Pause related callbacks are not supported on broadcast stream controllers.
Inherited from StreamController.
Implementation
abstract void Function()? onPause;
onResume read / write inherited#
getter:
The callback which is called when the stream is resumed.
May be set to null, in which case no callback will happen.
Pause related callbacks are not supported on broadcast stream controllers.
setter:
The callback which is called when the stream is resumed.
May be set to null, in which case no callback will happen.
Pause related callbacks are not supported on broadcast stream controllers.
Inherited from StreamController.
Implementation
abstract void Function()? onResume;
runtimeType no setter inherited#
A representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;
sink no setter inherited#
Returns a view of this object that only exposes the StreamSink interface.
Inherited from StreamController.
Implementation
StreamSink<T> get sink;
stream no setter inherited#
The stream that this controller is controlling.
Inherited from StreamController.
Implementation
Stream<T> get stream;
Methods#
add() inherited#
Sends a data event.
Listeners receive this event in a later microtask.
Note that a synchronous controller (created by passing true to the sync
parameter of the StreamController constructor) delivers events
immediately. Since this behavior violates the contract mentioned here,
synchronous controllers should only be used as described in the
documentation to ensure that the delivered events always appear as if
they were delivered in a separate microtask.
Inherited from StreamController.
Implementation
void add(T event);
addError() inherited#
Sends or enqueues an error event.
Listeners receive this event at a later microtask. This behavior can be
overridden by using sync controllers. Note, however, that sync
controllers have to satisfy the preconditions mentioned in the
documentation of the constructors.
Inherited from StreamController.
Implementation
void addError(Object error, [StackTrace? stackTrace]);
addErrorSync()#
Adds and delivers an error event.
Adds an error like addError and attempts to deliver it immediately. Delivery can be delayed if other previously added events are still pending delivery, if the subscription is paused, or if the subscription isn't listening yet.
Implementation
void addErrorSync(Object error, [StackTrace? stackTrace]);
addStream() inherited#
Receives events from source and puts them into this controller's stream.
Returns a future which completes when the source stream is done.
Events must not be added directly to this controller using add, addError, close or addStream, until the returned future is complete.
Data and error events are forwarded to this controller's stream. A done
event on the source will end the addStream operation and complete the
returned future.
If cancelOnError is true, only the first error on source is
forwarded to the controller's stream, and the addStream ends
after this. If cancelOnError is false, all errors are forwarded
and only a done event will end the addStream.
If cancelOnError is omitted or null, it defaults to
false.
Inherited from StreamController.
Implementation
Future addStream(Stream<T> source, {bool? cancelOnError});
addSync()#
Adds and delivers an event.
Adds an event like add and attempts to deliver it immediately. Delivery can be delayed if other previously added events are still pending delivery, if the subscription is paused, or if the subscription isn't listening yet.
Implementation
void addSync(T value);
close() inherited#
Closes the stream.
No further events can be added to a closed stream.
The returned future is the same future provided by done. It is completed when the stream listeners is done sending events, This happens either when the done event has been sent, or when the subscriber on a single-subscription stream is canceled.
A stream controller will not complete the returned future until all listeners present when the done event is sent have stopped listening. A listener will stop listening if it is cancelled, or if it has handled the done event. A paused listener will not process the done even until it is resumed, so completion of the returned Future will be delayed until all paused listeners have been resumed or cancelled.
If no one listens to a non-broadcast stream, or the listener pauses and never resumes, the done event will not be sent and this future will never complete.
Inherited from StreamController.
Implementation
Future close();
closeSync()#
Closes the controller and delivers a done event.
Closes the controller like close and attempts to deliver a "done" event immediately. Delivery can be delayed if other previously added events are still pending delivery, if the subscription is paused, or if the subscription isn't listening yet. If it's necessary to know whether the "done" event has been delivered, done future will complete when that has happened.
Implementation
void closeSync();
noSuchMethod() inherited#
Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time error
This invalid code will invoke the noSuchMethod method
of the integer 1 with an Invocation
representing the
.add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}
This code has no compile-time warnings or errors even though
the MockList class has no concrete implementation of
any of the List interface methods.
Calls to List methods are forwarded to noSuchMethod,
so this code will log an invocation similar to
Invocation.method(#add, [42])
and then throw.
If a value is returned from noSuchMethod,
it becomes the result of the original invocation.
If the value is not of a type that can be returned by the original
invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);
toString() inherited#
A string representation of this object.
Some classes have a default textual representation,
often paired with a static parse function (like int.parse).
These classes will provide the textual representation as
their string representation.
Other classes have no meaningful textual representation
that a program will care about.
Such classes will typically override toString to provide
useful information when inspecting the object,
mainly for debugging or logging.
Inherited from Object.
Implementation
external String toString();
Operators#
operator ==() inherited#
The equality operator.
The default behavior for all Objects is to return true if and
only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.-
Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false. -
Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Object.
Implementation
external bool operator ==(Object other);