Struct asyncio::IoContext
[−]
[src]
pub struct IoContext(_);
Methods
impl IoContext
[src]
fn new() -> Result<IoContext>
Returns a new IoContext
.
Panics
Panics if too many open files.
Examples
use asyncio::IoContext; IoContext::new().unwrap();
fn dispatch<F>(&self, func: F) where F: FnOnce(&IoContext) + Send + 'static
Requests a process to invoke the given handler.
Examples
use asyncio::IoContext; use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT}; static COUNT: AtomicUsize = ATOMIC_USIZE_INIT; let ctx = IoContext::new().unwrap(); ctx.dispatch(|_| { COUNT.fetch_add(1, Ordering::SeqCst); }); ctx.dispatch(|_| { COUNT.fetch_add(1, Ordering::SeqCst); }); ctx.dispatch(|_| { COUNT.fetch_add(1, Ordering::SeqCst); }); assert_eq!(COUNT.load(Ordering::Relaxed), 0); ctx.run(); assert_eq!(COUNT.load(Ordering::Relaxed), 3);
fn post<F>(&self, func: F) where F: FnOnce(&IoContext) + Send + 'static
Requests a process to invoke the given handler and return immediately.
Examples
use asyncio::IoContext; use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT}; static COUNT: AtomicUsize = ATOMIC_USIZE_INIT; let ctx = IoContext::new().unwrap(); ctx.post(|_| { COUNT.fetch_add(1, Ordering::SeqCst); }); ctx.post(|_| { COUNT.fetch_add(1, Ordering::SeqCst); }); ctx.post(|_| { COUNT.fetch_add(1, Ordering::SeqCst); }); assert_eq!(COUNT.load(Ordering::Relaxed), 0); ctx.run(); assert_eq!(COUNT.load(Ordering::Relaxed), 3);
fn restart(&self) -> bool
Resets a stopped IoContext
.
Examples
use asyncio::IoContext; let ctx = IoContext::new().unwrap(); assert_eq!(ctx.stopped(), false); ctx.stop(); assert_eq!(ctx.stopped(), true); ctx.restart(); assert_eq!(ctx.stopped(), false);
fn run(&self) -> usize
Runs all given handlers.
Examples
use asyncio::IoContext; let ctx = IoContext::new().unwrap(); ctx.run();
fn run_one(&self) -> usize
fn stop(&self)
Sets a stop request and cancel all of the waiting event in an IoContext
.
Examples
use asyncio::IoContext; let ctx = IoContext::new().unwrap(); ctx.stop();
fn stopped(&self) -> bool
Returns true if this has been stopped.
Examples
use asyncio::IoContext; let ctx = IoContext::new().unwrap(); assert_eq!(ctx.stopped(), false); ctx.stop(); assert_eq!(ctx.stopped(), true);
fn work(ctx: &IoContext) -> IoContextWork
impl IoContext
[src]
fn strand<'a, T>(ctx: &'a IoContext, data: T) -> StrandImmutable<'a, T>
impl IoContext
[src]
Trait Implementations
impl Clone for IoContext
[src]
fn clone(&self) -> IoContext
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more