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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#![warn(missing_docs)]
extern crate fibers;
extern crate futures;
extern crate inotify;
extern crate inotify_sys;
extern crate libc;
extern crate mio;
#[macro_use]
extern crate trackable;
#[doc(no_inline)]
pub use inotify::{EventMask, WatchMask};
pub use error::{Error, ErrorKind};
pub use internal_inotify::InotifyEvent;
pub use service::{InotifyService, InotifyServiceHandle};
pub use watcher::{Watcher, WatcherEvent};
mod error;
mod internal_inotify;
mod mio_ext;
mod service;
mod watcher;
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod test {
use std::thread;
use std::time::Duration;
use fibers::{Executor, InPlaceExecutor, Spawn};
use futures::{Future, Stream};
use super::*;
#[test]
fn it_works() {
let service = InotifyService::new();
let inotify = service.handle();
let mut executor = InPlaceExecutor::new().unwrap();
executor.spawn(service.map_err(|e| panic!("{}", e)));
executor.spawn(
inotify
.watch("/tmp/", WatchMask::all())
.for_each(|_event| Ok(()))
.map_err(|e| panic!("{}", e)),
);
executor.spawn(
inotify
.watch("/tmp/", WatchMask::CREATE)
.for_each(|_event| Ok(()))
.map_err(|e| panic!("{}", e)),
);
for _ in 0..500 {
executor.run_once().unwrap();
thread::sleep(Duration::from_millis(1));
}
}
}