toMpsc<T> method
Convert port messages to MPSC channel (legacy method).
Deprecated: Use toChannel with type: ChannelType.mpsc
for new code.
When strict == true
, the port is closed on unexpected message types.
Implementation
(MpscSender<T>, MpscReceiver<T>) toMpsc<T>({
int? capacity,
DropPolicy policy = DropPolicy.block,
OnDrop<T>? onDrop,
bool chunked = true,
bool strict = true,
String? metricsId,
}) {
final (tx, rx) = Mpsc.channel<T>(
capacity: capacity,
policy: policy,
onDrop: onDrop,
chunked: chunked,
metricsId: metricsId,
);
listen((msg) {
if (msg is T) {
final r = tx.trySend(msg);
if (r.isDisconnected) close();
} else if (strict) {
close();
}
});
return (tx, rx);
}