Struct open_coroutine::Events
source · pub struct Events { /* private fields */ }
Expand description
A collection of readiness events.
Events
is passed as an argument to Poll::poll
and will be used to
receive any new readiness events received since the last poll. Usually, a
single Events
instance is created at the same time as a Poll
and
reused on each call to Poll::poll
.
See Poll
for more documentation on polling.
Examples
use std::error::Error;
fn main() -> Result<(), Box> {
use mio::{Events, Poll}; use std::time::Duration;
let mut events = Events::with_capacity(1024); let mut poll = Poll::new()?;
assert!(events.is_empty());
// Register event::Source
s with poll
.
poll.poll(&mut events, Some(Duration::from_millis(100)))?;
for event in events.iter() { println!(“Got an event for {:?}”, event.token()); }
Ok(())
}
Implementations§
source§impl Events
impl Events
sourcepub fn with_capacity(capacity: usize) -> Events
pub fn with_capacity(capacity: usize) -> Events
Return a new Events
capable of holding up to capacity
events.
Examples
use base_coroutine::Events;
let events = Events::with_capacity(1024);
assert_eq!(1024, events.capacity());
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of Event
values that self
can hold.
use base_coroutine::Events;
let events = Events::with_capacity(1024);
assert_eq!(1024, events.capacity());
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if self
contains no Event
values.
Examples
use base_coroutine::Events;
let events = Events::with_capacity(1024);
assert!(events.is_empty());
sourcepub fn iter(&self) -> Iter<'_> ⓘ
pub fn iter(&self) -> Iter<'_> ⓘ
Returns an iterator over the Event
values.
Examples
use std::error::Error;
fn main() -> Result<(), Box> {
use base_coroutine::{Events, Poll}; use std::time::Duration;
let mut events = Events::with_capacity(1024); let mut poll = Poll::new()?;
// Register handles with poll
.
poll.poll(&mut events, Some(Duration::from_millis(100)))?;
for event in events.iter() { println!(“Got an event for {:?}”, event.token()); }
Ok(())
}
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clearing all Event
values from container explicitly.
Notes
Events are cleared before every poll
, so it is not required to call
this manually.
Examples
use std::error::Error;
fn main() -> Result<(), Box> {
use base_coroutine::{Events, Poll}; use std::time::Duration;
let mut events = Events::with_capacity(1024); let mut poll = Poll::new()?;
// Register handles with poll
.
poll.poll(&mut events, Some(Duration::from_millis(100)))?;
// Clear all events. events.clear(); assert!(events.is_empty());
Ok(())
}