Add input::stop_reading_thread() fn (#308)

This commit is contained in:
Zrzka 2019-11-04 18:41:27 +01:00 committed by Timon
parent 0107c76d4a
commit 827f9c1a72
3 changed files with 35 additions and 0 deletions

View File

@ -1,7 +1,16 @@
# master
- New `input::stop_reading_thread()` function
- Temporary workaround for the UNIX platform to stop the background
reading thread and close the file descriptor
- This function will be removed in the next version
# Version 0.13.1
- Async Reader fix, join background thread and avoid looping forever on windows.
# Version 0.13.0
**Major API-change, removed old-api**
- Remove `Crossterm` type

View File

@ -463,3 +463,18 @@ impl Command for DisableMouseCapture {
input().disable_mouse_mode()
}
}
/// Stops the reading thread.
///
/// # Notes
///
/// This function is a no-op on the Windows platform.
///
/// When you call this function on the UNIX platform, all event channel senders
/// are dropped and as a consequence you have to drop all `SyncReader`/`AsyncReader` readers.
pub fn stop_reading_thread() {
#[cfg(unix)]
{
sys::unix::stop_reading_thread();
}
}

View File

@ -50,6 +50,10 @@ mod utils {
}
}
pub(crate) fn stop_reading_thread() {
INTERNAL_EVENT_PROVIDER.lock().unwrap().pause()
}
/// An internal event provider interface.
pub(crate) trait InternalEventProvider: Send {
/// Pauses the provider.
@ -85,6 +89,12 @@ impl UnixInternalEventChannels {
}
}
/// Clears all senders.
fn clear(&mut self) {
let mut guard = self.senders.lock().unwrap();
guard.clear();
}
/// Sends an `InternalEvent` to all available channels.
///
/// # Notes
@ -129,6 +139,7 @@ impl InternalEventProvider for UnixInternalEventProvider {
fn pause(&mut self) {
// Thread will shutdown on it's own once dropped.
self.reading_thread = None;
self.channels.clear();
}
/// Creates a new `InternalEvent` receiver and spawns a new reading