Skip to content

nielsle/rust-actor-experiments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A few experiments with concurrency in rust.

I am trying to learn the language, so helpful comments are very welcome. So far the code looks like this:

extern mod actor;
extern mod std;

use actor::actor::{Actor, SurviveOrDie, Survive};
use actor::system::{System};

struct Squarer;

impl <C: GenericChan<int>> Actor<int, int, C> for Squarer {
    fn on_receive(&mut self, msg: int, chan: &C) -> SurviveOrDie {
        chan.send(msg * msg);
        Survive
    }
}

fn main() {

    let mut system = System::new();

    let mut squarers =
        do range(0, 6).map |i| {
            let squarer = system.add_actor((), |_| { Squarer });
            squarer.chan.send(i);
            squarer
        };

    let norm2 = squarers.fold(0, |sum, squarer| sum + squarer.port.recv());
    assert_eq!(norm2 , 1 * 1 + 2 * 2 + 3 * 3 + 4 * 4 + 5 * 5);
}```

About

[Deprecated] A few experiments with concurrency in rust.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages