pub struct PostgresCancelToken { /* private fields */ }Expand description
A token that can be used to cancel a running query on a PgConnection.
Obtained via PgConnection::cancel_token. Cancellation is a
best-effort signal: the server may have already finished processing the
query by the time the cancel request arrives, and the cancel request itself
is sent over a separate TCP connection with no acknowledgement.
This type is Send + Sync and can be passed to other tasks.
Implementations§
Source§impl PostgresCancelToken
impl PostgresCancelToken
Sourcepub async fn cancel_query<T>(&self, tls: T) -> Result<(), PgError>
pub async fn cancel_query<T>(&self, tls: T) -> Result<(), PgError>
Send a cancel request to the PostgreSQL server.
Uses tls to open the temporary cancel connection. Pass
tokio_postgres::NoTls for unencrypted connections, or the same TLS
connector used when establishing the main connection for encrypted ones.
Returns Ok(()) when the cancel request was sent (not when it was
acted upon — there is no acknowledgement in the PostgreSQL wire
protocol for cancel requests).
§Errors
Returns PgError::Connection if the cancel connection could not be
established or the cancel packet could not be sent.
§Example
use oxisql_postgres::{PgConnection, TlsMode};
let conn = PgConnection::connect("host=localhost user=postgres", TlsMode::Disabled).await?;
let token = conn.cancel_token().await;
// In another task:
token.cancel_query(tokio_postgres::NoTls).await?;