pub struct IoContext(/* private fields */);Implementations§
Source§impl IoContext
impl IoContext
Sourcepub fn dispatch<F>(&self, func: F)
pub fn dispatch<F>(&self, func: F)
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);Sourcepub fn post<F>(&self, func: F)
pub fn post<F>(&self, func: F)
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);Sourcepub fn restart(&self) -> bool
pub 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);Sourcepub fn run(&self) -> usize
pub fn run(&self) -> usize
Runs all given handlers.
§Examples
use asyncio::IoContext;
let ctx = IoContext::new().unwrap();
ctx.run();pub fn run_one(&self) -> usize
Sourcepub fn stop(&self)
pub 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();Sourcepub fn stopped(&self) -> bool
pub 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);pub fn work(ctx: &IoContext) -> IoContextWork
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for IoContext
impl !Sync for IoContext
impl !UnwindSafe for IoContext
impl Freeze for IoContext
impl Unpin for IoContext
impl UnsafeUnpin for IoContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more