Struct rust_tdlib::client::worker::Worker
source · pub struct Worker<A, S>where
A: AuthStateHandler + Send + Sync + 'static,
S: TdLibClient + Send + Sync + Clone + 'static,{ /* private fields */ }
Expand description
The main object in all interactions. You have to start worker and bind each client with worker using auth_client.
Implementations§
source§impl Worker<ConsoleAuthStateHandler, TdJson>
impl Worker<ConsoleAuthStateHandler, TdJson>
pub fn builder() -> WorkerBuilder<ConsoleAuthStateHandler, TdJson>
source§impl<A, T> Worker<A, T>where
A: AuthStateHandler + Send + Sync + 'static,
T: TdLibClient + Send + Sync + Clone + 'static,
impl<A, T> Worker<A, T>where A: AuthStateHandler + Send + Sync + 'static, T: TdLibClient + Send + Sync + Clone + 'static,
sourcepub async fn get_client_state(
&self,
client: &Client<T>
) -> Result<(ClientState, AuthorizationState)>
pub async fn get_client_state( &self, client: &Client<T> ) -> Result<(ClientState, AuthorizationState)>
Returns state of the client.
sourcepub async fn reset_auth(&mut self, client: &mut Client<T>) -> Result<()>
pub async fn reset_auth(&mut self, client: &mut Client<T>) -> Result<()>
Drops authorized client. After method call you cannot interact with TDLib by the client.
sourcepub async fn wait_auth_state_change(
&self,
client: &Client<T>
) -> Result<Result<ClientState, (Error, UpdateAuthorizationState)>>
pub async fn wait_auth_state_change( &self, client: &Client<T> ) -> Result<Result<ClientState, (Error, UpdateAuthorizationState)>>
Method waits for client state changes. If an error occured during authorization flow, you receive AuthorizationState on which it happened. You have to setup channel by call Client::builder().with_auth_state_channel(…)
sourcepub async fn wait_client_state(&self, client: &Client<T>) -> Result<ClientState>
pub async fn wait_client_state(&self, client: &Client<T>) -> Result<ClientState>
Method waits for client state changes. It differ from wait_auth_state_change by error type: you won’t receive (AuthorizationState)[crate::types::authorization_state::AuthorizationState] when error occured. Method may be useful if client already authorized on, for example, previous application startup.
sourcepub async fn bind_client(&mut self, client: Client<T>) -> Result<Client<T>>
pub async fn bind_client(&mut self, client: Client<T>) -> Result<Client<T>>
Binds client with worker and runs authorization routines. Method returns error if worker is not running or client already bound
pub async fn reload_client(&mut self, client: Client<T>) -> Result<Client<T>>
sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Determines that the worker is running.
sourcepub fn start(&mut self) -> JoinHandle<()>
pub fn start(&mut self) -> JoinHandle<()>
Starts interaction with TDLib. It returns JoinHandle which allows you to handle worker state: if it yields - so worker is definitely stopped.
sourcepub fn stop(&self)
pub fn stop(&self)
Stops the client.
You may want to await JoinHandle retrieved with client.start().await
after calling stop
.