vaas/
cancellation.rs

1//! # Cancellation
2//!
3//! As a request for a verdict can take some time if, for example the file is huge or the network connection is slow, it is possible to cancel
4//! each verdict request after some time. This is done by using a `CancellationToken` which can be created from a `Duration`.
5//! If the duration is up, the request is aborted and an error is returned.
6
7use std::time::Duration;
8
9/// The `CancellationToken` allows to cancel a request after a specific time
10/// if no response was received from the server.
11pub struct CancellationToken {
12    /// Duration after which the request is cancelled.
13    pub duration: Duration,
14}
15
16impl CancellationToken {
17    /// Create a new `CancellationToken` from seconds.
18    pub fn from_seconds(secs: u64) -> Self {
19        Self {
20            duration: Duration::from_secs(secs),
21        }
22    }
23
24    /// Create a new `CancellationToken` from minutes.
25    pub fn from_minutes(mins: u64) -> Self {
26        Self {
27            duration: Duration::from_secs(60 * mins),
28        }
29    }
30}