pub fn fetch_and_start_polling(&self) -> Result<(), Error> {
        if self.started.swap(true, Ordering::Relaxed) {
            return Err(Error::new(
                ErrorKind::AlreadyExists,
                "'start_polling' was already called",
            ));
        }

        let mut internal_state = InternalState::new(
            self.log.clone(),
            self.node_id,
            self.registry.clone(),
            self.local_store.clone(),
            self.poll_delay,
        );
        let res = internal_state
            .poll()
            .map_err(|err| Error::new(ErrorKind::Other, err));

        let log = self.log.clone();
        let cancelled = Arc::clone(&self.cancelled);
        let poll_delay = self.poll_delay;
        tokio::spawn(async move {
            let mut interval = tokio::time::interval(poll_delay);
            while !cancelled.load(Ordering::Relaxed) {
                let tick_time = interval.tick().await;
                // The relevant I/O-operation of the poll() function is querying
                // a node on the NNS for updates. As we set the query timeout to
                // `poll_delay` when constructing the underlying
                // `RegistryCanister` abstraction, we are guaranteed that
                // `poll()` returns after a maximal duration of `poll_delay`.
                if let Err(msg) = internal_state.poll() {
                    warn!(log, "Polling the NNS registry failed: {}", msg);
                } else {
                    debug!(log, "Polling the NNS succeeded.");
                }

                // Ticks happen at _absolute_ points in time. Thus, if the
                // delay between ticks (because, for example, under load the
                // scheduler cannot schedule this thread) is _longer_ than the
                // interval length, the intervals "pile up" and tick() will
                // immediately return a number of times.
                //
                // To prevent a situation where nodes start flooding the NNS
                // with requests, we simply reset the interval if the "skew"
                // becomes larger than poll_delay (or 2*poll_delay, accounting
                // for the maximum delay of poll() after the tick_time).
                if tokio::time::Instant::now().duration_since(tick_time) > 2 * poll_delay {
                    interval = tokio::time::interval(poll_delay);
                }
            }
        });
        res
    }
/// Calls `poll()` synchronously and spawns a background task that
/// continuously polls for updates. Returns the result of the first poll.
/// The background task is stopped when the object is dropped.
Calls `poll()` synchronously and spawns a background task that
continuously polls for updates. Returns the result of the first poll.
The background task is stopped when the object is dropped.
Calls ` poll () ` synchronously and spawns a background task that continuously polls for updates . Returns the result of the first poll . The background task is stopped when the object is dropped .
pub fn fetch_and_start_polling(&self) -> Result<(), Error> {
        if self.started.swap(true, Ordering::Relaxed) {
            return Err(Error::new(
                ErrorKind::AlreadyExists,
                "'start_polling' was already called",
            ));
        }
        let mut internal_state = InternalState::new(
            self.log.clone(),
            self.node_id,
            self.registry.clone(),
            self.local_store.clone(),
            self.poll_delay,
        );
        let res = internal_state
            .poll()
            .map_err(|err| Error::new(ErrorKind::Other, err));
        let log = self.log.clone();
        let cancelled = Arc::clone(&self.cancelled);
        let poll_delay = self.poll_delay;
        tokio::spawn(async move {
            let mut interval = tokio::time::interval(poll_delay);
            while !cancelled.load(Ordering::Relaxed) {
                let tick_time = interval.tick().await;
                // The relevant I/O-operation of the poll() function is querying
                // a node on the NNS for updates. As we set the query timeout to
                // `poll_delay` when constructing the underlying
                // `RegistryCanister` abstraction, we are guaranteed that
                // `poll()` returns after a maximal duration of `poll_delay`.
                if let Err(msg) = internal_state.poll() {
                    warn!(log, "Polling the NNS registry failed: {}", msg);
                } else {
                    debug!(log, "Polling the NNS succeeded.");
                }
                // Ticks happen at _absolute_ points in time. Thus, if the
                // delay between ticks (because, for example, under load the
                // scheduler cannot schedule this thread) is _longer_ than the
                // interval length, the intervals "pile up" and tick() will
                // immediately return a number of times.
                //
                // To prevent a situation where nodes start flooding the NNS
                // with requests, we simply reset the interval if the "skew"
                // becomes larger than poll_delay (or 2*poll_delay, accounting
                // for the maximum delay of poll() after the tick_time).
                if tokio::time::Instant::now().duration_since(tick_time) > 2 * poll_delay {
                    interval = tokio::time::interval(poll_delay);
                }
            }
        });
        res
    }
pub fn fetch_and_start_polling ( & self ) -> Result < ( ) , Error > { if self . started . swap ( true , Ordering :: Relaxed ) { return Err ( Error :: new ( ErrorKind :: AlreadyExists , " " , ) ) ; } let mut internal_state = InternalState :: new ( self . log . clone ( ) , self . node_id , self . registry . clone ( ) , self . local_store . clone ( ) , self . poll_delay , ) ; let res = internal_state . poll ( ) . map_err ( | err | Error :: new ( ErrorKind :: Other , err ) ) ; let log = self . log . clone ( ) ; let cancelled = Arc :: clone ( & self . cancelled ) ; let poll_delay = self . poll_delay ; tokio :: spawn ( async move { let mut interval = tokio :: time :: interval ( poll_delay ) ; while ! cancelled . load ( Ordering :: Relaxed ) { let tick_time = interval . tick ( ) . await ; // The relevant I/O-operation of the poll() function is querying // a node on the NNS for updates. As we set the query timeout to // `poll_delay` when constructing the underlying // `RegistryCanister` abstraction, we are guaranteed that // `poll()` returns after a maximal duration of `poll_delay`. if let Err ( msg ) = internal_state . poll ( ) { warn ! ( log " " msg ) ; } else { debug ! ( log " " ) ; } // Ticks happen at _absolute_ points in time. Thus, if the // delay between ticks (because, for example, under load the // scheduler cannot schedule this thread) is _longer_ than the // interval length, the intervals "pile up" and tick() will // immediately return a number of times. // // To prevent a situation where nodes start flooding the NNS // with requests, we simply reset the interval if the "skew" // becomes larger than poll_delay (or 2*poll_delay, accounting // for the maximum delay of poll() after the tick_time). if tokio :: time :: Instant :: now ( ) . duration_since ( tick_time ) > 2 * poll_delay { interval = tokio :: time :: interval ( poll_delay ) ; } } } ) ; res }
Calls `poll()` synchronously and spawns a background task that
continuously polls for updates.
Calls ` poll () ` synchronously and spawns a background task that continuously polls for updates .
&self
&self