pub struct Watchers(/* private fields */);
Expand description
Wraps all watcher connections observing one directory. The directory is responsible for
calling Self::add()
and Self::send_event()
method when appropriate to make sure
watchers are observing a consistent view.
Implementations§
Source§impl Watchers
impl Watchers
Sourcepub fn add(
&mut self,
scope: ExecutionScope,
directory: Arc<dyn Directory>,
mask: WatchMask,
watcher: DirectoryWatcher,
) -> Arc<Controller>
pub fn add( &mut self, scope: ExecutionScope, directory: Arc<dyn Directory>, mask: WatchMask, watcher: DirectoryWatcher, ) -> Arc<Controller>
Connects a new watcher (connected over the channel
) to the list of watchers. It is the
responsibility of the caller to also send WATCH_EVENT_EXISTING
and WatchMask::IDLE
events on the returned Controller
to the newly connected watcher using the
Self::send_event
methods. This mask
is the event mask this watcher has requested.
Return value of None
means the executor did not accept a new task, so the watcher has
been dropped.
NOTE The reason add
can not send both events on its own by consuming an
EventProducer
is because a lazy directory needs async context to generate a list of
it’s entries. Meaning we need a async version of the EventProducer
- and that is a lot
of additional managing of functions and state. Traits do not support async methods yet, so
we would need to manage futures returned by the EventProducer
methods explicitly.
Plus, for the crate::directory::immutable::Simple
directory it is all unnecessary.
Sourcepub fn send_event(&mut self, producer: &mut dyn EventProducer)
pub fn send_event(&mut self, producer: &mut dyn EventProducer)
Informs all the connected watchers about the specified event. While mask
and event
carry the same information, as they are represented by WatchMask::*
and WATCH_EVENT_*
constants in fuchsia.io, it is easier when both forms are provided. mask
is used to
filter out those watchers that did not request for observation of this event and event
is
used to construct the event object. The method will operate correctly only if mask
and
event
match.
In case of a communication error with any of the watchers, connection to this watcher is closed.