Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
39
third-party/vendor/inotify/examples/stream.rs
vendored
Normal file
39
third-party/vendor/inotify/examples/stream.rs
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use std::{
|
||||
fs::File,
|
||||
io,
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use futures_util::StreamExt;
|
||||
use inotify::{
|
||||
Inotify,
|
||||
WatchMask,
|
||||
};
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), io::Error> {
|
||||
let mut inotify = Inotify::init()
|
||||
.expect("Failed to initialize inotify");
|
||||
|
||||
let dir = TempDir::new()?;
|
||||
|
||||
inotify.add_watch(dir.path(), WatchMask::CREATE | WatchMask::MODIFY)?;
|
||||
|
||||
thread::spawn::<_, Result<(), io::Error>>(move || {
|
||||
loop {
|
||||
File::create(dir.path().join("file"))?;
|
||||
thread::sleep(Duration::from_millis(500));
|
||||
}
|
||||
});
|
||||
|
||||
let mut buffer = [0; 1024];
|
||||
let mut stream = inotify.event_stream(&mut buffer)?;
|
||||
|
||||
while let Some(event_or_error) = stream.next().await {
|
||||
println!("event: {:?}", event_or_error?);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue