Struct asyncio::IoService [] [src]

pub struct IoService(_);

Provides core I/O functionality.

Methods

impl IoService
[src]

Returns a new IoService.

Panics

Panics if too many open files.

Examples

use asyncio::IoService;

let io = IoService::new();

Requests a process to invoke the given handler.

Examples

use asyncio::IoService;
use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT};

static COUNT: AtomicUsize = ATOMIC_USIZE_INIT;

let io = IoService::new();
io.dispatch(|_| { COUNT.fetch_add(1, Ordering::SeqCst); });
io.dispatch(|_| { COUNT.fetch_add(1, Ordering::SeqCst); });
io.dispatch(|_| { COUNT.fetch_add(1, Ordering::SeqCst); });
io.run();

assert_eq!(COUNT.load(Ordering::Relaxed), 3);

Requests a process to invoke the given handler and return immediately.

Examples

use asyncio::IoService;
use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT};

static COUNT: AtomicUsize = ATOMIC_USIZE_INIT;

let io = IoService::new();
io.post(|_| { COUNT.fetch_add(1, Ordering::SeqCst); });
io.post(|_| { COUNT.fetch_add(1, Ordering::SeqCst); });
io.post(|_| { COUNT.fetch_add(1, Ordering::SeqCst); });
io.run();

assert_eq!(COUNT.load(Ordering::Relaxed), 3);

Resets a stopped IoService.

Examples

use asyncio::IoService;

let io = IoService::new();
assert_eq!(io.stopped(), false);
io.stop();
assert_eq!(io.stopped(), true);
io.reset();
assert_eq!(io.stopped(), false);

Runs all given handlers.

Examples

use asyncio::IoService;

let io = IoService::new();
io.run();

Sets a stop request and cancel all of the waiting event in an IoService.

Examples

use asyncio::IoService;

let io = IoService::new();
io.stop();

Returns true if this has been stopped.

Examples

use asyncio::IoService;

let io = IoService::new();
assert_eq!(io.stopped(), false);
io.stop();
assert_eq!(io.stopped(), true);

Returns a IoServiceWork associated the IoService.

Examples

use asyncio::IoService;

let io = IoService::new();
let mut work = Some(IoService::work(&io));
assert_eq!(io.stopped(), false);
work = None;
assert_eq!(io.stopped(), true);

Returns a strand associated the IoService.

Examples

use asyncio::IoService;
let io = &IoService::new();
let st = IoService::strand(io, 0);
st.post(move |mut st| *st = 1);
assert_eq!(*st, 0);
io.run();
assert_eq!(*st, 1);

Starts a new stackful coroutine.

Examples

use asyncio::IoService;
use std::sync::atomic::{Ordering, AtomicBool, ATOMIC_BOOL_INIT};

static PASS: AtomicBool = ATOMIC_BOOL_INIT;

let io = &IoService::new();
IoService::spawn(io, |co| {
  PASS.store(true, Ordering::SeqCst);
});
assert_eq!(PASS.load(Ordering::Relaxed), false);
io.run();
assert_eq!(PASS.load(Ordering::Relaxed), true);

Trait Implementations

impl Clone for IoService
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for IoService
[src]

Formats the value using the given formatter.

impl IoObject for IoService
[src]

Returns a IoService associated with this object.