genawaiter/sync/
engine.rs1use crate::{core, core::Next};
2use std::{
3 mem,
4 sync::{Arc, Mutex},
5};
6
7pub struct Airlock<Y, R>(Arc<Mutex<Next<Y, R>>>);
8
9impl<Y, R> Default for Airlock<Y, R> {
10 fn default() -> Self {
11 Self(Arc::new(Mutex::new(Next::Empty)))
12 }
13}
14
15impl<Y, R> Clone for Airlock<Y, R> {
16 fn clone(&self) -> Self {
17 Self(self.0.clone())
18 }
19}
20
21impl<Y, R> core::Airlock for Airlock<Y, R> {
22 type Yield = Y;
23 type Resume = R;
24
25 fn peek(&self) -> Next<(), ()> {
26 self.0.lock().unwrap().without_values()
27 }
28
29 fn replace(&self, next: Next<Y, R>) -> Next<Y, R> {
30 mem::replace(&mut self.0.lock().unwrap(), next)
31 }
32}
33
34pub type Co<Y, R = ()> = core::Co<Airlock<Y, R>>;