chromedriver_api/
manager.rs1use crate::prelude::*;
2
3#[derive(Debug, Clone)]
5pub struct TaskManager {
6 state: Arc<Mutex<bool>>, notify: Arc<Notify>,
8}
9
10impl TaskManager {
11 pub fn new() -> Self {
13 Self {
14 state: Arc::new(Mutex::new(false)),
15 notify: Arc::new(Notify::new()),
16 }
17 }
18
19 pub async fn lock(&self) {
21 loop {
22 {
23 let mut locked = self.state.lock().await;
24 if !*locked {
25 *locked = true;
26 return;
27 }
28 }
29
30 self.notify.notified().await;
31 }
32 }
33
34 pub async fn unlock(&self) {
36 {
37 let mut locked = self.state.lock().await;
38 *locked = false;
39 }
40
41 self.notify.notify_waiters();
42 }
43}