1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::HttpClient;
use std::sync::atomic::{AtomicBool, Ordering};
use async_std::sync::Mutex;
pub struct Session {
id: Mutex<String>,
pub http: HttpClient,
#[allow(dead_code)]
pub(crate) state: (),
is_resumable: AtomicBool,
}
impl Session {
pub(crate) fn new(token: String) -> Self {
Session {
id: Mutex::new("".into()),
http: HttpClient::new(token),
state: (),
is_resumable: AtomicBool::new(true),
}
}
pub(crate) fn set_resumable(&self, b: bool) {
self.is_resumable.store(b, Ordering::Relaxed);
}
pub(crate) fn is_resumable(&self) -> bool {
self.is_resumable.load(Ordering::Relaxed)
}
pub(crate) async fn set_id(&self, id: String) {
let mut session_id = self.id.lock().await;
*session_id = id;
}
pub(crate) async fn id(&self) -> String {
let session_id = self.id.lock().await;
session_id.clone()
}
}