From 02e47b758f0c187a4e91885c8f7079692726c082 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Mon, 28 Mar 2022 16:37:12 +0200 Subject: [PATCH] cleanup --- examples/timer.rs | 59 ----------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 examples/timer.rs diff --git a/examples/timer.rs b/examples/timer.rs deleted file mode 100644 index 90965752..00000000 --- a/examples/timer.rs +++ /dev/null @@ -1,59 +0,0 @@ -use chrono::prelude::*; -use std::{ - thread::sleep}; - -fn get_timestamp() -> i64 { - let local: DateTime = Local::now(); - - local.timestamp_millis() as i64 -} - -struct Timer { - init: bool, - timestamp: i64, - limit: i64, - messages: Vec, -} - -impl Timer { - fn new() -> Self { - Self { - init: true, - timestamp: get_timestamp(), - limit: 10 * 1000, - messages: vec![], - } - } - - fn reset(&mut self) { - self.messages.clear(); - self.timestamp = get_timestamp(); - } - - fn send(&mut self, msg: String) { - let now = get_timestamp(); - self.messages.push(msg); - - if self.init { - self.reset(); - self.init = false; - } - - if now >= self.timestamp + self.limit { - println!("Send messages: {:?}", self.messages); - - self.reset(); - } - } -} - -fn main() { - let mut timer = Timer::new(); - - for i in 0..40 { - println!("{:?}", i); - timer.send(format!("{:?}", i)); - - sleep(std::time::Duration::from_secs(1)); - } -}