Struct asyncio::IoContext [] [src]

pub struct IoContext(_);

Methods

impl IoContext
[src]

Returns a new IoContext.

Panics

Panics if too many open files.

Examples

use asyncio::IoContext;

IoContext::new().unwrap();

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);

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);

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);

Runs all given handlers.

Examples

use asyncio::IoContext;

let ctx = IoContext::new().unwrap();
ctx.run();

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();

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);

impl IoContext
[src]

impl IoContext
[src]

Trait Implementations

impl Clone for IoContext
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for IoContext
[src]

Formats the value using the given formatter.

impl AsIoContext for IoContext
[src]

impl Send for IoContext
[src]