pub fn poll(timeout: Duration) -> Result<bool>
Expand description
Checks if there is an Event
available.
Returns Ok(true)
if an Event
is available otherwise it returns Ok(false)
.
Ok(true)
guarantees that subsequent call to the read
function
won’t block.
§Arguments
timeout
- maximum waiting time for event availability
§Examples
Return immediately:
use std::{time::Duration, io};
use crossterm::{event::poll};
fn is_event_available() -> io::Result<bool> {
// Zero duration says that the `poll` function must return immediately
// with an `Event` availability information
poll(Duration::from_secs(0))
}
Wait up to 100ms:
use std::{time::Duration, io};
use crossterm::event::poll;
fn is_event_available() -> io::Result<bool> {
// Wait for an `Event` availability for 100ms. It returns immediately
// if an `Event` is/becomes available.
poll(Duration::from_millis(100))
}