|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +use std::error::Error; |
| 18 | + |
| 19 | +use crate::consumer::ack_result::AckResult; |
| 20 | + |
| 21 | +/// Trait representing an acknowledgment callback. |
| 22 | +/// This trait defines two methods: `on_success` and `on_exception`. |
| 23 | +pub trait AckCallback { |
| 24 | + /// Called when the acknowledgment is successful. |
| 25 | + /// |
| 26 | + /// # Arguments |
| 27 | + /// |
| 28 | + /// * `ack_result` - The result of the acknowledgment. |
| 29 | + fn on_success(&self, ack_result: AckResult); |
| 30 | + |
| 31 | + /// Called when there is an exception during acknowledgment. |
| 32 | + /// |
| 33 | + /// # Arguments |
| 34 | + /// |
| 35 | + /// * `e` - The error that occurred. |
| 36 | + fn on_exception(&self, e: Box<dyn Error>); |
| 37 | +} |
| 38 | + |
| 39 | +/// Type alias for a function that acts as an acknowledgment callback. |
| 40 | +/// The function takes two optional arguments: an `AckResult` and an error. |
| 41 | +/// |
| 42 | +/// This type alias is used to define a callback function that can be passed |
| 43 | +/// around and invoked when an acknowledgment operation completes. |
| 44 | +/// |
| 45 | +/// The function must be `Send` and `Sync` to ensure it can be safely used |
| 46 | +/// across threads. |
| 47 | +pub type AckCallbackFn = Box<dyn Fn(Option<AckResult>, Option<Box<dyn Error>>) + Send + Sync>; |
0 commit comments