mirror of
https://github.com/denoland/deno.git
synced 2024-11-27 16:10:57 -05:00
fix: handle showing warnings while the progress bar is shown (#25187)
This commit is contained in:
parent
38bc4021e6
commit
bbd3a7e637
2 changed files with 18 additions and 7 deletions
|
@ -40,7 +40,7 @@ struct InternalEntry {
|
|||
struct InternalState {
|
||||
// this ensures only one actual draw thread is running
|
||||
drawer_id: usize,
|
||||
hide: bool,
|
||||
hide_count: usize,
|
||||
has_draw_thread: bool,
|
||||
next_entry_id: u16,
|
||||
entries: Vec<InternalEntry>,
|
||||
|
@ -56,7 +56,7 @@ impl InternalState {
|
|||
static INTERNAL_STATE: Lazy<Arc<Mutex<InternalState>>> = Lazy::new(|| {
|
||||
Arc::new(Mutex::new(InternalState {
|
||||
drawer_id: 0,
|
||||
hide: false,
|
||||
hide_count: 0,
|
||||
has_draw_thread: false,
|
||||
entries: Vec::new(),
|
||||
next_entry_id: 0,
|
||||
|
@ -113,7 +113,7 @@ impl DrawThread {
|
|||
pub fn hide() {
|
||||
let internal_state = &*INTERNAL_STATE;
|
||||
let mut internal_state = internal_state.lock();
|
||||
internal_state.hide = true;
|
||||
internal_state.hide_count += 1;
|
||||
|
||||
Self::clear_and_stop_draw_thread(&mut internal_state);
|
||||
}
|
||||
|
@ -122,10 +122,13 @@ impl DrawThread {
|
|||
pub fn show() {
|
||||
let internal_state = &*INTERNAL_STATE;
|
||||
let mut internal_state = internal_state.lock();
|
||||
internal_state.hide = false;
|
||||
|
||||
if internal_state.hide_count > 0 {
|
||||
internal_state.hide_count -= 1;
|
||||
if internal_state.hide_count == 0 {
|
||||
Self::maybe_start_draw_thread(&mut internal_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn finish_entry(entry_id: u16) {
|
||||
let internal_state = &*INTERNAL_STATE;
|
||||
|
@ -153,7 +156,7 @@ impl DrawThread {
|
|||
|
||||
fn maybe_start_draw_thread(internal_state: &mut InternalState) {
|
||||
if internal_state.has_draw_thread
|
||||
|| internal_state.hide
|
||||
|| internal_state.hide_count > 0
|
||||
|| internal_state.entries.is_empty()
|
||||
|| !DrawThread::is_supported()
|
||||
{
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use std::io::Write;
|
||||
|
||||
use super::draw_thread::DrawThread;
|
||||
|
||||
struct CliLogger(env_logger::Logger);
|
||||
|
||||
impl CliLogger {
|
||||
|
@ -21,7 +23,13 @@ impl log::Log for CliLogger {
|
|||
|
||||
fn log(&self, record: &log::Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
// it was considered to hold the draw thread's internal lock
|
||||
// across logging, but if outputting to stderr blocks then that
|
||||
// could potentially block other threads that access the draw
|
||||
// thread's state
|
||||
DrawThread::hide();
|
||||
self.0.log(record);
|
||||
DrawThread::show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue