pub struct Worker<A, S>{ /* 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>
impl<A, T> Worker<A, T>
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
.