pub struct AbortController { /* private fields */ }
Expand description
A controller for managing abort signals.
AbortController
provides a way to create and control AbortSignal
s.
It follows the DOM AbortController specification and allows for cancelling
operations by calling the abort()
method.
Each controller manages exactly one signal, which can be retrieved using
the signal()
method. The signal can be cloned and shared as needed.
§Examples
use fetchttp::AbortController;
let controller = AbortController::new();
let signal = controller.signal().clone();
// Use the signal in an operation
assert!(!signal.aborted());
// Cancel the operation
controller.abort();
assert!(signal.aborted());
Implementations§
Source§impl AbortController
impl AbortController
Sourcepub fn signal(&self) -> &AbortSignal
pub fn signal(&self) -> &AbortSignal
Get a reference to the signal managed by this controller.
The signal can be cloned and shared as needed. All clones will reflect the same abort state.
§Returns
A reference to the AbortSignal
managed by this controller.
§Examples
use fetchttp::AbortController;
let controller = AbortController::new();
let signal1 = controller.signal().clone();
let signal2 = controller.signal().clone();
// Both signals will show the same state
controller.abort();
assert!(signal1.aborted());
assert!(signal2.aborted());
Sourcepub fn abort(&self)
pub fn abort(&self)
Abort the signal managed by this controller.
This method aborts the signal with a default reason of “AbortError”. Once aborted, the signal cannot be un-aborted.
§Examples
use fetchttp::AbortController;
let controller = AbortController::new();
let signal = controller.signal();
assert!(!signal.aborted());
controller.abort();
assert!(signal.aborted());
assert_eq!(signal.reason().unwrap(), "AbortError");
Trait Implementations§
Source§impl Debug for AbortController
impl Debug for AbortController
Auto Trait Implementations§
impl Freeze for AbortController
impl RefUnwindSafe for AbortController
impl Send for AbortController
impl Sync for AbortController
impl Unpin for AbortController
impl UnwindSafe for AbortController
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