http_types/upgrade/sender.rs
1use crate::upgrade::Connection;
2
3/// The sending half of a channel to send an upgraded connection.
4///
5/// Unlike `async_channel::Sender` the `send` method on this type can only be
6/// called once, and cannot be cloned. That's because only a single instance of
7/// `Connection` should be created.
8#[derive(Debug)]
9pub struct Sender {
10 sender: async_channel::Sender<Connection>,
11}
12
13impl Sender {
14 /// Create a new instance of `Sender`.
15 #[doc(hidden)]
16 pub fn new(sender: async_channel::Sender<Connection>) -> Self {
17 Self { sender }
18 }
19
20 /// Send a `Connection`.
21 ///
22 /// The channel will be consumed after having sent the connection.
23 pub async fn send(self, conn: Connection) {
24 let _ = self.sender.send(conn).await;
25 }
26}