toMpsc<T> method
(MpscSender<T> , MpscReceiver<T> )
toMpsc<T>({
- int? capacity,
- DropPolicy policy = DropPolicy.block,
- OnDrop<
T> ? onDrop, - bool chunked = true,
- bool strict = true,
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,
}) {
final (tx, rx) = Mpsc.channel<T>(
capacity: capacity,
policy: policy,
onDrop: onDrop,
chunked: chunked,
);
onmessage = ((MessageEvent msg) {
final data = msg.data.dartify();
if (data is T) {
final r = tx.trySend(data);
if (r.isDisconnected) close();
} else if (strict) {
close();
}
}).toJS;
return (tx, rx);
}