rocketmq_rust/netty_rust/
timer.rs

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 */
17use std::collections::HashSet;
18use std::sync::Arc;
19use std::time::Duration;
20
21use crate::netty_rust::timeout::Timeout;
22use crate::netty_rust::timer_task::TimerTask;
23
24/// convert from netty [Timer](https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/Timer.java)
25/// A trait representing a timer that can schedule and manage timed tasks.
26#[allow(dead_code)]
27pub trait Timer: Send + Sync {
28    /// Schedules a new timeout task to be executed after the specified delay.
29    ///
30    /// # Arguments
31    ///
32    /// * `task` - An `Arc` containing the task to be executed.
33    /// * `delay` - The duration to wait before executing the task.
34    ///
35    /// # Returns
36    ///
37    /// An `Arc` containing the scheduled timeout.
38    fn new_timeout(&self, task: Arc<dyn TimerTask>, delay: Duration) -> Arc<dyn Timeout>;
39
40    /// Stops the timer and cancels all scheduled tasks.
41    ///
42    /// # Returns
43    ///
44    /// A `HashSet` containing all the cancelled timeouts.
45    fn stop(&self) -> HashSet<Arc<dyn Timeout>>;
46}