Struct rust_asio::Strand [] [src]

pub struct Strand<'a, T> {
    // some fields omitted
}

Serialized object for an IoService.

This is cannot Send and Sync, but possible to move another thread in event loop.

Examples

use asio::{IoObject, IoService, Strand};
use std::thread;

let mut thrds = Vec::new();
IoService::new().work(|io| {
    for _ in 0..4 {
        let io = io.clone();
        thrds.push(thread::spawn(move || io.run()));
    }

    fn closure(mut counter: Strand<usize>) {
        if *counter != 100 {
            *counter += 1;
            counter.io_service().post_strand(closure, &counter);
        }
    }
    for _ in 0..10 {
        closure(Strand::new(io, 0));
    }

    io.stop();
});

for thrd in thrds {
    thrd.join().unwrap();
}

Methods

impl<'a, T> Strand<'a, T>
[src]

fn new(io: &'a IoService, t: T) -> Strand<'a, T>

Make a Strand wrapped value.

Examples

use asio::{IoService, Strand};

let io = IoService::new();
let obj = Strand::new(&io, false);
assert_eq!(*obj, false);

Trait Implementations

impl<'a, T> IoObject for Strand<'a, T>
[src]

fn io_service(&self) -> &IoService

Returns a IoService associated with this object.

impl<'a, T> Deref for Strand<'a, T>
[src]

type Target = T

The resulting type after dereferencing

fn deref(&self) -> &Self::Target

The method called to dereference a value

impl<'a, T> DerefMut for Strand<'a, T>
[src]

fn deref_mut(&mut self) -> &mut Self::Target

The method called to mutably dereference a value