Skip to main content

nomux_extension/
call.rs

1//! One call of a method of the extension.
2
3use std::sync::Arc;
4use std::sync::atomic::{AtomicBool, Ordering};
5
6use crate::host::Host;
7
8/// The context of one call. Each method gets it as its first argument.
9pub struct Call {
10    pub(crate) host: Host,
11    pub(crate) cancelled: Arc<AtomicBool>,
12}
13
14impl Call {
15    /// The host that sent the call.
16    pub fn host(&self) -> &Host {
17        &self.host
18    }
19
20    /// Returns `true` after the host cancelled the call.
21    ///
22    /// A method that can run for a long time examines this value between its
23    /// steps and returns [`crate::CallError::cancelled`] when it is `true`.
24    pub fn is_cancelled(&self) -> bool {
25        self.cancelled.load(Ordering::Relaxed)
26    }
27}