Skip to main content

on_error

Function on_error 

Source
pub fn on_error(callback: impl Fn(Error) + Send + Sync + 'static)
Expand description

Installs or replaces the process-wide unsolicited-error callback.

Reports malformed native output and unsolicited TDLib errors without a waiting request recipient, including errors with unknown client IDs. Correlated request failures are returned to their caller instead. Without a callback these diagnostics are unobserved; they do not enter unrelated clients’ update queues.

The callback is synchronous on the native receiver thread while the callback lock is held. It must not block, panic, call on_error again, invoke execute, or wait for work that needs the receiver. Copy/forward the error to application-owned processing when more work is needed. A panic can terminate the receiver; there is no automatic restart or poison recovery. Replacing the callback also drops the old callback under its lock.

This is not a native log subscription. To stop observing, replace the callback with a no-op; there is no separate unsubscribe handle.

§Examples

use std::sync::mpsc;
use td_client::on_error;

let (errors, receiver) = mpsc::channel();
on_error(move |error| {
  // Unbounded send does not wait for application processing.
  let _ = errors.send(error);
});
// An application-owned worker can now consume receiver.