Hey Dartisans,
I just published a new package called
stream_channel and I want to talk it up a bit. It fills in a hole in the Dart asynchrony landscape by providing a standard way of representing two-way communication: the eponymous
StreamChannel class.
The interface itself is extremely simple:
abstract class StreamChannel<T> {
/// The single-subscription stream that emits values from the
/// other endpoint.
Stream<T> get stream;
/// The sink for sending values to the other endpoint.
StreamSink<T> get sink;
}
There are also a few utility methods, but those can easily be implemented in terms of
stream and
sink using
StreamChannelMixin.
This package will make it easier to deal with two-way communication in a general way, without being tightly coupled to context-specific APIs like
ReceivePort or
WebSocket. I'm planning on migrating packages like
shelf_web_socket that handle two-way communication to use
StreamChannels very soon.
Enjoy!
- Natalie