-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow more than channels and make crossbeam optional
- Loading branch information
Showing
5 changed files
with
194 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::{path::Path, time::Duration}; | ||
|
||
use notify::{RecursiveMode, Watcher}; | ||
use notify_debouncer_mini::new_debouncer; | ||
|
||
/// Debouncer with custom backend and waiting for exit | ||
fn main() { | ||
std::thread::spawn(|| { | ||
let path = Path::new("test.txt"); | ||
let _ = std::fs::remove_file(&path); | ||
loop { | ||
std::fs::write(&path, b"Lorem ipsum").unwrap(); | ||
std::thread::sleep(Duration::from_millis(250)); | ||
} | ||
}); | ||
|
||
let (tx, rx) = std::sync::mpsc::channel(); | ||
|
||
let mut debouncer = new_debouncer_opt::<_,notify::PollWatcher>(Duration::from_secs(2), None, tx).unwrap(); | ||
|
||
debouncer | ||
.watcher() | ||
.watch(Path::new("."), RecursiveMode::Recursive) | ||
.unwrap(); | ||
|
||
for events in rx { | ||
for e in events { | ||
println!("{:?}", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,26 @@ | |
name = "notify-debouncer-mini" | ||
version = "0.1.0" | ||
edition = "2021" | ||
rust-version = "1.56" | ||
description = "notify mini debouncer for events" | ||
documentation = "https://docs.rs/notify_debouncer_mini" | ||
homepage = "https://github.com/notify-rs/notify" | ||
repository = "https://github.com/notify-rs/notify.git" | ||
authors = ["Aron Heinecke <[email protected]>"] | ||
keywords = ["events", "filesystem", "notify", "watch"] | ||
license = "CC0-1.0 OR Artistic-2.0" | ||
readme = "README.md" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
name = "notify_debouncer_mini" | ||
path = "src/lib.rs" | ||
|
||
[features] | ||
default = ["crossbeam-channel"] | ||
|
||
[dependencies] | ||
notify = "5.0.0-pre.15" | ||
notify = "5.0.0-pre.15" | ||
crossbeam-channel = { version = "0.5", optional = true } | ||
serde = { version = "1.0.89", features = ["derive"], optional = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Notify debouncer | ||
|
||
Tiny debouncer for notify. Filters incoming events and emits only one event per timeframe per file. | ||
|
||
## Features | ||
|
||
- `crossbeam` enabled by default, for crossbeam channel support. | ||
This may create problems used in tokio environments. See [#380](https://github.com/notify-rs/notify/issues/380). | ||
Use someting like `notify-debouncer-mini = { version = "*", default-features = false }` to disable it. | ||
- `serde` for serde support of event types, off by default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters