coap_server/app/
observable_resource.rs

1use async_trait::async_trait;
2
3use crate::app::observers::Observers;
4
5/// Special manager-like type which is responsible for brokering support between the
6/// core server infrastructure and individual resource handlers.
7#[async_trait]
8pub trait ObservableResource: 'static {
9    /// Invoked when the first observer is registered for a given path (see
10    /// [`Observers::relative_path`]).  An [`Observers`] instance
11    /// is provided as a handle to inform the server when changes are detected which can be stored
12    /// and used.  When this method completes all current observers for the given path will be
13    /// removed.  For this reason, most customers should prefer to simply await on
14    /// [`Observers::stay_active`] which ensures the method will not complete until all observers
15    /// are gone.
16    ///
17    /// This method is a good place to initiate any potentially expensive watch operation
18    /// that may be necessary to support observation of the associated resource.
19    ///
20    /// This method is guaranteed to not be called concurrently for any given path (i.e. `on_active`
21    /// will block another call to `on_active`, but only for a specific path).
22    async fn on_active(&self, observers: Observers) -> Observers;
23}