File: notify.rs

package info (click to toggle)
rust-polling 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 412 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 760 bytes parent folder | download | duplicates (2)
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
use std::io;
use std::thread;
use std::time::Duration;

use easy_parallel::Parallel;
use polling::Events;
use polling::Poller;

#[test]
fn simple() -> io::Result<()> {
    let poller = Poller::new()?;
    let mut events = Events::new();

    for _ in 0..10 {
        poller.notify()?;
        poller.wait(&mut events, None)?;
        assert!(events.is_empty());
    }

    Ok(())
}

#[test]
fn concurrent() -> io::Result<()> {
    let poller = Poller::new()?;
    let mut events = Events::new();

    for _ in 0..2 {
        Parallel::new()
            .add(|| {
                thread::sleep(Duration::from_secs(0));
                poller.notify().unwrap();
            })
            .finish(|| poller.wait(&mut events, None).unwrap());
    }

    Ok(())
}