forked from amqp-rs/lapin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer_canceler.rs
41 lines (38 loc) · 960 Bytes
/
consumer_canceler.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::{
consumer_status::{ConsumerState, ConsumerStatus},
internal_rpc::InternalRPCHandle,
types::ChannelId,
};
pub(crate) struct ConsumerCanceler {
channel_id: ChannelId,
consumer_tag: String,
status: ConsumerStatus,
internal_rpc: InternalRPCHandle,
}
impl ConsumerCanceler {
pub(crate) fn new(
channel_id: ChannelId,
consumer_tag: String,
status: ConsumerStatus,
internal_rpc: InternalRPCHandle,
) -> Self {
Self {
channel_id,
consumer_tag,
status,
internal_rpc,
}
}
}
impl Drop for ConsumerCanceler {
fn drop(&mut self) {
let status = self.status.lock();
if status.state() == ConsumerState::Active {
self.internal_rpc.cancel_consumer(
self.channel_id,
self.consumer_tag.clone(),
self.status.clone(),
);
}
}
}