Add input::stop_reading_thread()
fn (#308)
This commit is contained in:
parent
0107c76d4a
commit
827f9c1a72
@ -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
|
||||
|
15
src/input.rs
15
src/input.rs
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user