Add cleaning of buffers to separate worker thread

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 09c4776321
commit 32e85dae7a

@ -8,7 +8,7 @@ pub fn register_custom_uri_schemes<R: Runtime>(builder: Builder<R>) -> Builder<R
let resource_key = request.uri().trim_start_matches("once://");
let buffer = buf_state.get_entry(resource_key);
buf_state.clear_expired();
if let Some(buffer) = buffer {
ResponseBuilder::new()
.mimetype(&buffer.mime)

@ -4,6 +4,8 @@ use tauri::{AppHandle, Builder, Invoke, Manager, Runtime};
use state::ApiState;
use crate::tauri_plugin::state::{AppState, BufferState};
use std::thread;
use std::time::Duration;
pub(crate) mod commands;
pub mod custom_schemes;
@ -58,7 +60,11 @@ impl<R: Runtime> Plugin<R> for MediarepoPlugin<R> {
app.manage(api_state);
let buffer_state = BufferState::default();
app.manage(buffer_state);
app.manage(buffer_state.clone());
thread::spawn(move || loop {
thread::sleep(Duration::from_secs(10));
buffer_state.clear_expired();
});
let repo_state = AppState::load()?;
app.manage(repo_state);

@ -58,7 +58,7 @@ impl VolatileBuffer {
}
}
#[derive(Default)]
#[derive(Default, Clone)]
pub struct BufferState {
pub buffer: Arc<Mutex<HashMap<String, VolatileBuffer>>>,
}

Loading…
Cancel
Save