-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: cutecutecat <junyuchen@tensorchord.ai>
- Loading branch information
1 parent
2d38087
commit 80c326a
Showing
7 changed files
with
123 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use super::Index; | ||
use crate::prelude::*; | ||
use base::index::IndexFlexibleOptions; | ||
use std::sync::Arc; | ||
|
||
pub struct FlexibleOptionSyncing<S: G> { | ||
index: Arc<Index<S>>, | ||
} | ||
|
||
impl<S: G> FlexibleOptionSyncing<S> { | ||
pub fn new(index: Arc<Index<S>>) -> Self { | ||
Self { index } | ||
} | ||
pub fn spawn(self) { | ||
std::thread::spawn(move || { | ||
self.main(); | ||
}); | ||
} | ||
pub fn main(self) { | ||
let index = self.index; | ||
let weak_index = Arc::downgrade(&index); | ||
let mut old_options = index.flexible.clone(); | ||
drop(index); | ||
loop { | ||
{ | ||
let Some(index) = weak_index.upgrade() else { | ||
return; | ||
}; | ||
let new_options = index.flexible.clone(); | ||
if new_options != old_options { | ||
std::fs::write( | ||
index.path.join("flexible"), | ||
serde_json::to_string::<IndexFlexibleOptions>(&new_options).unwrap(), | ||
) | ||
.unwrap(); | ||
old_options = new_options; | ||
} | ||
} | ||
std::thread::sleep(std::time::Duration::from_secs(5)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters