1
0
mirror of https://github.com/djcb/mu.git synced 2024-06-26 07:29:17 +02:00

server: make indexing asynchronous

Perform indexing in a background thread.
This commit is contained in:
Dirk-Jan C. Binnema 2022-02-03 22:59:47 +02:00
parent b6d7d142f6
commit 4d0ecf7f85

View File

@ -58,6 +58,13 @@ struct Server::Private {
keep_going_{true} keep_going_{true}
{ {
} }
~Private()
{
indexer().stop();
if (index_thread_.joinable())
index_thread_.join();
}
// //
// construction helpers // construction helpers
// //
@ -129,6 +136,7 @@ private:
Server::Output output_; Server::Output output_;
const CommandMap command_map_; const CommandMap command_map_;
std::atomic<bool> keep_going_{}; std::atomic<bool> keep_going_{};
std::thread index_thread_;
}; };
static Sexp static Sexp
@ -773,13 +781,18 @@ Server::Private::index_handler(const Parameters& params)
conf.ignore_noupdate = store().empty(); conf.ignore_noupdate = store().empty();
indexer().stop(); indexer().stop();
if (index_thread_.joinable())
index_thread_.join();
indexer().start(conf); // start a background track.
while (indexer().is_running()) { index_thread_ = std::thread([this, conf = std::move(conf)] {
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); indexer().start(conf);
output_sexp(get_stats(indexer().progress(), "running")); while (indexer().is_running()) {
} std::this_thread::sleep_for(std::chrono::milliseconds(2000));
output_sexp(get_stats(indexer().progress(), "complete")); output_sexp(get_stats(indexer().progress(), "running"), true);
}
output_sexp(get_stats(indexer().progress(), "complete"));
});
} }
void void