summaryrefslogtreecommitdiff
path: root/support/texlab/src/server/query.rs
blob: f19d15f85bccf44735f6911d908b139d87256cc1 (plain)
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
use salsa::{DbWithJar, ParallelDatabase};
use threadpool::ThreadPool;

use crate::{Database, Db};

#[derive(Default)]
pub struct Engine {
    db: Database,
    pool: ThreadPool,
}

impl Engine {
    pub fn read(&self) -> &dyn Db {
        &self.db
    }

    pub fn write(&mut self) -> &mut dyn Db {
        self.pool.join();
        &mut self.db
    }

    pub fn fork<F: FnOnce(&dyn Db) + Send + 'static>(&self, action: F) {
        let snapshot = self.db.snapshot();
        self.pool.execute(move || {
            action(snapshot.as_jar_db());
        });
    }

    pub fn finish(self) {
        self.pool.join();
    }
}