bottle 0.1.0

Actor model framework for Rust.
extern crate num_cpus;
extern crate signals;

use signals::{MutHandler, Signal, Remote, Future, SimpleScheduler, Scheduler};

struct Foo {
	n: u32
}

trait RemoteFoo {
	fn incr(&self) -> Future<u32>;
}

impl RemoteFoo for Remote<Foo> {
	fn incr(&self) -> Future<u32> {
		self.send_mut(Incr)
	}
}

struct Incr;
impl Signal for Incr {
    type Response = u32;
}

impl Foo {
    fn incr(&mut self) -> u32 {
        self.n += 1;
        self.n
    }
}

impl MutHandler<Incr> for Foo {
	fn handle_mut(&mut self, _msg: Incr) -> u32 {
		println!("incr");
		self.n += 1;
		self.n
	}
}

fn main() {
    let scheduler = SimpleScheduler::new(num_cpus::get());

	let foo = scheduler.handle(Foo { n: 0 });
	foo.incr();
	foo.incr();
	foo.incr();

	for thread in scheduler.start().drain(..) {
		thread.join();
	}
}