pub struct CancelHandle { /* private fields */ }Expand description
Handle to cancel an in-flight streaming request.
Call cancel to signal the stream to stop. The stream will emit
a final StreamEnd { finish_reason: Some("cancelled") } and then terminate.
§Example
ⓘ
let (stream, cancel_handle) = client.chat()
.messages(msgs)
.stream()
.execute_stream_with_cancel()
.await?;
// Cancel from another task or on user action
tokio::spawn(async move {
tokio::time::sleep(Duration::from_secs(5)).await;
cancel_handle.cancel();
});Implementations§
Source§impl CancelHandle
impl CancelHandle
Auto Trait Implementations§
impl Freeze for CancelHandle
impl !RefUnwindSafe for CancelHandle
impl Send for CancelHandle
impl Sync for CancelHandle
impl Unpin for CancelHandle
impl UnsafeUnpin for CancelHandle
impl !UnwindSafe for CancelHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more