treacle
A generic event debouncer for Rust, for grouping events which occur close together in time into a single event.
For example, you may have some templates which you want to reload whenever a template file changes. However, if many small changes are made to the template files in quick succession, it would be wasteful to reload the templates for every change; instead, a debouncer could be used to group the changes that occur at a similar time into a single change, so the templates are only reloaded once.
A new debouncer can be created with the
debouncer
function, which returns the debouncer in two halves: a tx (send) half and rx (receive) half. The
tx sends raw un-debounced events to the debouncer, and the rx receives the debounced events from
the debouncer. Both halves can be cloned to allow for multiple senders and receivers.
use ;
// Create a new debouncer which takes raw events of type `u32` and outputs
// debounced events of type `Vec<u32>`.
let = ;
spawn;
assert_eq!;
assert_eq!;