pub struct PollerThread { /* private fields */ }Expand description
A configuration poller thread.
The poller thread polls the server periodically to fetch the latest configuration.
Use Client::start_poller_thread to get an instance.
The Client returns None for assignments before the first configuration is fetched. So it is
recommended to call PollerThread::wait_for_configuration before requesting assignments.
Implementations§
Source§impl PollerThread
impl PollerThread
Sourcepub fn wait_for_configuration(&self) -> Result<()>
👎Deprecated
pub fn wait_for_configuration(&self) -> Result<()>
Waits for the configuration to be fetched.
This method blocks until the poller thread has fetched the configuration.
§Note
This function may block indefinitely. It is recommended to use
PollerThread::wait_for_configuration_timeout instead.
§Returns
Returns Result<()> where Ok(()) indicates successful configuration fetch and any
error that occurred during the process.
§Errors
This method can fail with the following errors:
Error::PollerThreadPanicked: If the poller thread panicked while waiting for configuration.
§Example
let poller = client.start_poller_thread().unwrap();
match poller.wait_for_configuration() {
Ok(()) => println!("Configuration fetched successfully."),
Err(err) => eprintln!("Error fetching configuration: {:?}", err),
}Sourcepub fn wait_for_configuration_timeout(&self, duration: Duration) -> Result<()>
pub fn wait_for_configuration_timeout(&self, duration: Duration) -> Result<()>
Waits for the configuration to be fetched (or timed out).
This method blocks until the poller thread has fetched the configuration or timeout occurs.
§Returns
Returns Result<()> where Ok(()) indicates successful configuration fetch and any
error that occurred during the process.
§Errors
This method can fail with the following errors:
Error::PollerThreadPanicked: If the poller thread panicked while waiting for configuration.Error::Timeout: If timeout reached without producing configuration.
§Example
let poller = client.start_poller_thread().unwrap();
match poller.wait_for_configuration_timeout(Duration::from_secs(5)) {
Ok(()) => println!("Configuration fetched successfully."),
Err(err) => eprintln!("Error fetching configuration: {:?}", err),
}Sourcepub fn stop(&self)
pub fn stop(&self)
Stop the poller thread.
This function does not wait for the thread to actually stop.
Sourcepub fn shutdown(self) -> Result<()>
pub fn shutdown(self) -> Result<()>
Stop the poller thread and block waiting for it to exit.
If you don’t need to wait for the thread to exit, use PollerThread::stop instead.
§Errors
Returns an error of type Error in the following cases:
Error::PollerThreadPanickedif the thread has panicked.
§Examples
poller_thread.shutdown().expect("Failed to shut down the poller thread");