MultiChannel< T> class
A class that multiplexes multiple virtual channels across a single underlying transport layer.
This should be connected to another MultiChannel on the other end of the underlying channel. It starts with a single default virtual channel, accessible via stream and sink. Additional virtual channels can be created with virtualChannel.
When a virtual channel is created by one endpoint, the other must connect to it before messages may be sent through it. The first endpoint passes its VirtualChannel.id to the second, which then creates a channel from that id also using virtualChannel. For example:
// First endpoint
var virtual = multiChannel.virtualChannel();
multiChannel.sink.add({
"channel": virtual.id
});
// Second endpoint
multiChannel.stream.listen((message) {
var virtual = multiChannel.virtualChannel(message["channel"]);
// ...
});
Sending errors across a MultiChannel is not supported. Any errors from the underlying stream will be reported only via the default MultiChannel.stream.
Each virtual channel may be closed individually. When all of them are closed, the underlying StreamSink is closed automatically.
- Implemented types
- Implementers
Constructors
- MultiChannel(StreamChannel inner)
-
Creates a new MultiChannel that sends and receives messages over
inner
. [...]factory
Properties
-
sink
→ StreamSink<
T> -
The default output stream. [...]
read-only, override
-
stream
→ Stream<
T> -
The default input stream. [...]
read-only, override
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
virtualChannel(
[int id ]) → VirtualChannel< T> - Creates a new virtual channel. [...]
-
cast<
S>( ) → StreamChannel< S> -
Returns a copy of this with the generic type coerced to
S
. [...]inherited -
changeSink(
StreamSink< T> change(StreamSink< T> sink)) → StreamChannel< T> -
Returns a copy of this with
sink
replaced bychange
's return value.inherited -
changeStream(
Stream< T> change(Stream< T> stream)) → StreamChannel< T> -
Returns a copy of this with
stream
replaced bychange
's return value.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
pipe(
StreamChannel< T> other) → void -
Connects this to
other
, so that any values emitted by either are sent directly to the other.inherited -
toString(
) → String -
Returns a string representation of this object.
inherited
-
transform<
S>( StreamChannelTransformer< S, T> transformer) → StreamChannel< S> -
Transforms this using
transformer
. [...]inherited -
transformSink(
StreamSinkTransformer< T, T> transformer) → StreamChannel< T> -
Transforms only the sink component of this using
transformer
.inherited -
transformStream(
StreamTransformer< T, T> transformer) → StreamChannel< T> -
Transforms only the stream component of this using
transformer
.inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited