channel method
Converts this port to a two-way communication channel, exposed as a
StreamChannel
.
This can be used to implement a remote database connection over service workers.
Implementation
StreamChannel<Object?> channel() {
final controller = StreamChannelController();
onMessage.map((event) => event.data).pipe(controller.local.sink);
controller.local.stream.listen(postMessage, onDone: close);
return controller.foreign;
}