tianjia
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
use crate::pri_key::PriKey;
|
use crate::pri_key::PriKey;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
use std::thread::JoinHandle;
|
||||||
|
|
||||||
const LOOP_NUMBERS: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 97, 98, 99, 100, 101, 102];
|
const LOOP_NUMBERS: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 97, 98, 99, 100, 101, 102];
|
||||||
static mut TASK_MAP: LazyLock<HashMap<u32, Task>> = LazyLock::new(|| {
|
static mut TASK_MAP: LazyLock<HashMap<u32, Task>> = LazyLock::new(|| {
|
||||||
@@ -15,9 +16,21 @@ pub struct Task {
|
|||||||
pub pri_key: PriKey,
|
pub pri_key: PriKey,
|
||||||
pub target_addr: String,
|
pub target_addr: String,
|
||||||
pub stop: bool,
|
pub stop: bool,
|
||||||
|
pub handle: Option<JoinHandle< ()>>
|
||||||
}
|
}
|
||||||
impl Task {
|
impl Task {
|
||||||
pub fn new(id:u32,pri_key: PriKey, target_addr: String) -> Self {
|
pub fn new(id:u32,pri_key: PriKey, target_addr: String) -> Self {
|
||||||
Task { id, pri_key, target_addr,stop: false }
|
Task { id, pri_key, target_addr,stop: false, handle: None }
|
||||||
|
}
|
||||||
|
pub fn start(&mut self) {
|
||||||
|
self.handle = Some(std::thread::spawn(|| {
|
||||||
|
let mut i = 0;
|
||||||
|
while !self.stop {
|
||||||
|
let tx = self.pri_key.send_tx(self.target_addr.clone(), LOOP_NUMBERS[i].to_string());
|
||||||
|
println!("{:?}", tx);
|
||||||
|
i = (i + 1) % LOOP_NUMBERS.len();
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user