blob: f671f9b3399df94bbde5891c019a7c6616dd3f6b [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use futures::channel::mpsc;
#[derive(Debug)]
pub struct UnboundedSink<T> {
sink: mpsc::UnboundedSender<T>,
}
impl<T> UnboundedSink<T> {
pub fn new(sink: mpsc::UnboundedSender<T>) -> Self {
UnboundedSink { sink }
}
pub fn send(&self, msg: T) {
match self.sink.unbounded_send(msg) {
Ok(()) => {}
Err(e) => {
if e.is_full() {
panic!("Did not expect an unbounded channel to be full: {:?}", e);
}
// If the other side has disconnected, we can still technically function,
// so ignore the error.
}
}
}
}
pub type MlmeSink = UnboundedSink<crate::MlmeRequest>;
pub type InfoSink = UnboundedSink<crate::InfoEvent>;