use threadpool for all threads to be able to have unified panic handling

This commit is contained in:
Stephan Dilly 2020-03-26 10:05:50 +01:00
parent 314d76e0c2
commit 1d58365b33
2 changed files with 10 additions and 6 deletions

View file

@ -14,6 +14,7 @@ use crossterm::{
},
ExecutableCommand, Result,
};
use log::error;
use scopetime::scope_time;
use simplelog::*;
use std::{env, fs, fs::File, io};
@ -34,13 +35,16 @@ fn main() -> Result<()> {
let mut app = App::new(tx_git);
let rx_input = poll::start_polling_thread();
rayon_core::ThreadPoolBuilder::new()
.panic_handler(|e| panic!(e))
.panic_handler(|e| {
error!("thread panic: {:?}", e);
panic!(e)
})
.build_global()
.unwrap();
let rx_input = poll::start_polling_thread();
app.update();
loop {

View file

@ -2,7 +2,7 @@ use asyncgit::AsyncNotification;
use crossbeam_channel::{unbounded, Receiver};
use crossterm::event::{self, Event};
use std::{
thread::{self, sleep},
thread::sleep,
time::{Duration, Instant},
};
@ -27,7 +27,7 @@ pub fn start_polling_thread() -> Receiver<Vec<QueueEvent>> {
let (tx, rx) = unbounded();
let tx1 = tx.clone();
thread::spawn(move || {
rayon_core::spawn(move || {
let mut last_send = Instant::now();
let mut batch = Vec::new();
@ -51,7 +51,7 @@ pub fn start_polling_thread() -> Receiver<Vec<QueueEvent>> {
}
});
thread::spawn(move || loop {
rayon_core::spawn(move || loop {
tx.send(vec![QueueEvent::Tick]).unwrap();
sleep(TICK_DURATION);
});