The Handler has a fn ack(self) and a fn nack(self). If the application drops the handler without calling either, we continue to hold the message in lease management, and continue to extend its lease, even though it can never be acknowledged by the application.
We should nack messages on drop. And we should consider just getting rid of h.nack(), when we can drop(h) instead.
To implement this, we will want to hold an inner state in an option1. Something like:
struct AtLeastOnce {
inner: Option<AtLeastOnceImpl>;
}
impl AtLeastOnce {
fn ack(self) {
if let Some(inner) = std::mem::take(self.inner) {
inner.ack(); // or whatever.
}
}
}
impl Drop for AtLeastOnce {
fn drop(&mut self) {
if let Some(inner) = std::mem::take(self.inner) {
inner.nack(); // or whatever.
}
}
}
The
Handlerhas afn ack(self)and afn nack(self). If the application drops the handler without calling either, we continue to hold the message in lease management, and continue to extend its lease, even though it can never be acknowledged by the application.We should nack messages on drop. And we should consider just getting rid of
h.nack(), when we candrop(h)instead.To implement this, we will want to hold an inner state in an option1. Something like:
Footnotes
We cannot consume
selffor structs that have a manual drop. Unless we are willing to beunsafe. ↩