rustque/
response.rs

1use std::sync::Arc;
2use tokio::sync::Mutex;
3use crate::workers::{Signal,SignalData,Pointer};
4use tokio::sync::Notify;
5
6#[derive(Debug,Clone)]
7pub struct QueResponse{
8    signal:Arc<Mutex<Signal>>,
9    sleeper:Arc<Notify>
10}
11
12impl QueResponse{
13    pub fn new(signal:Arc<Mutex<Signal>>,sleeper:Arc<Notify>)->QueResponse{
14        QueResponse{
15            signal:signal,
16            sleeper:sleeper
17        }
18    }
19    pub async fn check(&self)->bool{
20        self.sleeper.notified().await;
21        if !Signal::check(&self.signal).await{
22            return false;
23        } else {
24            return true;
25        }
26    }
27    pub async fn data(self)->Option<(Vec<u8>,Pointer)>{
28        match Signal::get(self.signal).await{
29            Ok(v)=>{
30                match v{
31                    SignalData::Value(v)=>{
32                        Some(v)
33                    },
34                    _=>{None}
35                }
36            },
37            Err(_)=>{
38                return None;
39            }
40        }
41    }
42}