Skip to content

Commit 2260b65

Browse files
committed
Updating code for passing tests everywhere.
1 parent 156dda9 commit 2260b65

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ serde_json = "1.0"
4444
# because that leads to unexpected behavior and flaky tests, so we need
4545
# to run thoses tests in sequence instead.
4646
serial_test = "0.4"
47+
tokio = {version = "1.5", features=["sync", "macros", "rt-multi-thread"]}
4748

4849
[[example]]
4950
name = "serialize"
@@ -53,6 +54,10 @@ required-features = ["serialize"]
5354
name = "grab"
5455
required-features = ["unstable_grab"]
5556

57+
[[example]]
58+
name = "tokio_channel"
59+
required-features = ["unstable_grab"]
60+
5661
[[test]]
5762
name = "grab"
5863
path = "tests/grab.rs"

examples/tokio_channel.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use rdev::listen;
2+
use std::thread;
3+
use tokio::sync::mpsc;
4+
5+
#[tokio::main]
6+
async fn main() {
7+
// spawn new thread because listen blocks
8+
let (schan, mut rchan) = mpsc::unbounded_channel();
9+
let _listener = thread::spawn(move || {
10+
listen(move |event| {
11+
schan
12+
.send(event)
13+
.unwrap_or_else(|e| println!("Could not send event {:?}", e));
14+
})
15+
.expect("Could not listen");
16+
});
17+
18+
loop {
19+
let event = rchan.recv().await;
20+
println!("Received {:?}", event);
21+
}
22+
}

src/macos/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(clippy::upper-case-acronym)]
12
use crate::macos::keyboard::Keyboard;
23
use crate::rdev::{Button, Event, EventType};
34
use cocoa::base::id;

src/macos/keyboard.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(clippy::upper-case-acronym)]
12
use crate::macos::keycodes::code_from_key;
23
use crate::rdev::{EventType, Key, KeyboardState};
34
use core_foundation::base::{CFRelease, OSStatus};

0 commit comments

Comments
 (0)