Skip to content

Commit b1c9b45

Browse files
committed
Add cancel_query
1 parent f754391 commit b1c9b45

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

postgres-tokio/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ pub struct CancelData {
5757
pub secret_key: i32,
5858
}
5959

60+
pub fn cancel_query<T>(params: T,
61+
tls_mode: TlsMode,
62+
cancel_data: CancelData,
63+
handle: &Handle)
64+
-> BoxFuture<(), ConnectError>
65+
where T: IntoConnectParams
66+
{
67+
let params = match params.into_connect_params() {
68+
Ok(params) => {
69+
Either::A(stream::connect(params.host().clone(), params.port(), tls_mode, handle))
70+
}
71+
Err(e) => Either::B(Err(ConnectError::ConnectParams(e)).into_future())
72+
};
73+
74+
params.and_then(move |c| {
75+
let mut buf = vec![];
76+
frontend::cancel_request(cancel_data.process_id, cancel_data.secret_key, &mut buf);
77+
c.send(buf).map_err(ConnectError::Io)
78+
})
79+
.map(|_| ())
80+
.boxed()
81+
}
82+
6083
struct InnerConnection {
6184
stream: PostgresStream,
6285
close_receiver: Receiver<(u8, String)>,

0 commit comments

Comments
 (0)