mirror of
https://github.com/sigoden/aichat
synced 2024-11-16 06:15:26 +00:00
7c6841782d
- move model_info.rs/message.rs to clients/ - rename SharedConfig to GlobalConfig
56 lines
1.1 KiB
Rust
56 lines
1.1 KiB
Rust
use std::sync::{
|
|
atomic::{AtomicBool, Ordering},
|
|
Arc,
|
|
};
|
|
|
|
pub type AbortSignal = Arc<AbortSignalInner>;
|
|
|
|
pub struct AbortSignalInner {
|
|
ctrlc: AtomicBool,
|
|
ctrld: AtomicBool,
|
|
}
|
|
|
|
pub fn create_abort_signal() -> AbortSignal {
|
|
AbortSignalInner::new()
|
|
}
|
|
|
|
impl AbortSignalInner {
|
|
pub fn new() -> AbortSignal {
|
|
Arc::new(Self {
|
|
ctrlc: AtomicBool::new(false),
|
|
ctrld: AtomicBool::new(false),
|
|
})
|
|
}
|
|
|
|
pub fn aborted(&self) -> bool {
|
|
if self.aborted_ctrlc() {
|
|
return true;
|
|
}
|
|
if self.aborted_ctrld() {
|
|
return true;
|
|
}
|
|
false
|
|
}
|
|
|
|
pub fn aborted_ctrlc(&self) -> bool {
|
|
self.ctrlc.load(Ordering::SeqCst)
|
|
}
|
|
|
|
pub fn aborted_ctrld(&self) -> bool {
|
|
self.ctrld.load(Ordering::SeqCst)
|
|
}
|
|
|
|
pub fn reset(&self) {
|
|
self.ctrlc.store(false, Ordering::SeqCst);
|
|
self.ctrld.store(false, Ordering::SeqCst);
|
|
}
|
|
|
|
pub fn set_ctrlc(&self) {
|
|
self.ctrlc.store(true, Ordering::SeqCst);
|
|
}
|
|
|
|
pub fn set_ctrld(&self) {
|
|
self.ctrld.store(true, Ordering::SeqCst);
|
|
}
|
|
}
|