-
Notifications
You must be signed in to change notification settings - Fork 4
/
0053-bottle.rs
83 lines (67 loc) · 1.69 KB
/
0053-bottle.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*!
```rudra-poc
[target]
crate = "bottle"
version = "1.1.0-alpha"
[[target.peer]]
crate = "async-std"
version = "1.7.0"
features = ["attributes"]
[test]
cargo_toolchain = "nightly"
[report]
issue_url = "https://github.com/timothee-haudebourg/bottle/issues/1"
issue_date = 2020-12-07
[[bugs]]
analyzer = "Manual"
guide = "SendSyncVariance"
bug_class = "Other"
bug_count = 2
rudra_report_locations = []
```
!*/
#![forbid(unsafe_code)]
#![feature(arbitrary_self_types)]
use std::time::Duration;
use async_std::future;
use bottle::{Event, EventQueue, Handler, Output, Receiver, Remote};
struct EmptyEvent;
impl Event for EmptyEvent {
type Response = ();
}
struct UninitChecker {
// magic value, should be always 0x12345678
magic: u64,
}
impl UninitChecker {
pub fn new() -> Self {
UninitChecker {
magic: 0x12345678
}
}
pub fn validate(&self) {
if self.magic != 0x12345678 {
panic!("Uninitialized value access! 0x{:x}", self.magic);
}
}
}
impl Handler<EmptyEvent> for UninitChecker {
fn handle(self: Receiver<Self>, _event: EmptyEvent) -> Output<'static, ()> {
self.validate();
Output::Now(())
}
}
#[async_std::main]
async fn main() {
let queue1 = EventQueue::new();
let queue1_ref = queue1.reference();
let queue2 = EventQueue::new();
let queue2_ref = queue2.reference();
let remote = Remote::from(queue1_ref, || UninitChecker::new());
std::thread::spawn(move || {
async_std::task::block_on(queue2.process())
});
if let Err(_timeout) = future::timeout(Duration::from_secs(1), queue2_ref.push(remote.clone(), EmptyEvent)).await {
println!("Future timeout");
}
}