[−][src]Function crossterm::event::poll
pub fn poll(timeout: Duration) -> Result<bool>
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
wont block.
Arguments
timeout
- maximum waiting time for event availability
Examples
Return immediately:
use std::time::Duration; use crossterm::{event::poll, Result}; fn is_event_available() -> 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; use crossterm::{event::poll, Result}; fn is_event_available() -> Result<bool> { // Wait for an `Event` availability for 100ms. It returns immediately // if an `Event` is/becomes available. poll(Duration::from_millis(100)) }