crossterm
crossterm copied to clipboard
Guard for flushing
Is your feature request related to a problem? Please describe. Currently you can forget to flush a set of commands
Describe the solution you'd like
When you call queue, you get an object that you write events to, and then when you drop it those events are flushed, or you can call flush directly if you want to handle errors.
This would look like (roughly)
fn queue(&'a self) -> QueueGuard<'a>;
impl QueueGuard {
pub fn execute(&self cmd: Command);
pub fn flush(self) -> Result<()>;
fn flush_inner(&mut self) -> Result<()>; // needed so we can share code between flush and drop.
}
impl Drop for QueueGuard {
fn drop(&mut self) {
#[allow(unused_must_use)]
self.flush_inner();
}
}
Additional context
This is how working with Mutexes works in std.
It sounds like a nice idea, some kind of queue guard that always flushes automatically at some adjustable setting. BufWrite also does something similar tough, it is customized for the most performant situation for IO operations. Maybe you can use that as well for those situations.