pub enum ReceiveResult<T> {
Message(Box<ReceivedMessage<T>>),
Shutdown,
ConnectionLost {
reason: String,
},
Timeout,
ChannelClosed,
ConsumerCancelled,
Retryable {
reason: String,
retry_after: Option<Duration>,
},
}Expand description
Result of a receive operation from a message backend.
This enum provides explicit semantics for different receive outcomes, allowing callers to distinguish between graceful shutdown, connection loss, transient errors, and successful message receipt.
§Examples
use foxtive_worker::backends::ReceiveResult;
async fn process_messages(backend: &dyn foxtive_worker::backends::MessageBackend) -> anyhow::Result<()> {
loop {
match backend.receive().await? {
ReceiveResult::Message(msg) => {
// Process the message
println!("Received: {}", msg.message.id);
}
ReceiveResult::Shutdown => {
// Backend is shutting down gracefully
break;
}
ReceiveResult::ConnectionLost { reason } => {
// Connection lost - trigger reconnection
eprintln!("Connection lost: {}", reason);
return Err(anyhow::anyhow!("Connection lost: {}", reason));
}
_ => {
// Handle other cases
}
}
}
Ok(())
}Variants§
Message(Box<ReceivedMessage<T>>)
Message received successfully
Shutdown
Backend is shutting down gracefully (shutdown() was called)
ConnectionLost
Connection lost - requires reconnection
Timeout
Operation timed out
ChannelClosed
Consumer channel was closed unexpectedly
ConsumerCancelled
Consumer was cancelled by broker or client
Retryable
Transient error that may resolve on retry
Implementations§
Source§impl<T> ReceiveResult<T>
impl<T> ReceiveResult<T>
Sourcepub fn is_message(&self) -> bool
pub fn is_message(&self) -> bool
Check if a message was received
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Check if the backend is shutting down
Sourcepub fn needs_reconnection(&self) -> bool
pub fn needs_reconnection(&self) -> bool
Check if reconnection is needed
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Check if the operation should be retried
Sourcepub fn into_message(self) -> Option<ReceivedMessage<T>>
pub fn into_message(self) -> Option<ReceivedMessage<T>>
Extract the message if present
Sourcepub fn status_str(&self) -> &'static str
pub fn status_str(&self) -> &'static str
Get a description of the result status
Trait Implementations§
Source§impl<T: Debug> Debug for ReceiveResult<T>
impl<T: Debug> Debug for ReceiveResult<T>
Source§impl<T> Display for ReceiveResult<T>
impl<T> Display for ReceiveResult<T>
Source§impl<T> Error for ReceiveResult<T>
impl<T> Error for ReceiveResult<T>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()