seal_rs 0.3.2

Set of classic asynchronous primitives (Actors, Executors, Futures / Promises)
Documentation
use crate::actors::actor::Actor;
use crate::actors::actor_context::ActorContext;
use std::any::Any;
use std::time::{SystemTime};


pub struct Tick {}

pub struct FictionOne {
    pub x: String
}

pub struct FictionTwo {
    pub x: u32
}

pub struct FictionThree {
    pub x: u128
}


pub struct Bench {
    count: u32,
    threshold: u32,
    start_time: SystemTime
}

impl Bench {
    pub fn new() -> Bench {
        Bench {
            count: 0,
            threshold: 250000,
            start_time: SystemTime::now()
        }
    }
}

impl Actor for Bench {
    fn receive(self: &mut Self, msg: &Box<Any + Send>, ctx: ActorContext) -> bool {

        if let Some(FictionOne { x }) = msg.downcast_ref::<FictionOne>() {
            println!("FictionOne")
        } else  if let Some(FictionTwo { x }) = msg.downcast_ref::<FictionTwo>() {
            println!("FictionTwo")
        } else  if let Some(FictionThree { x }) = msg.downcast_ref::<FictionThree>() {
            println!("FictionTree")
        } else  if let Some(Tick {}) = msg.downcast_ref::<Tick>() {
            if self.threshold == 0 {
                self.start_time = SystemTime::now()
            }

            self.count = self.count + 1;

            if self.count == self.threshold {
                println!("Total time ms = {}", self.start_time.elapsed().unwrap().as_millis())
            }
        } else {
            println!("Unknown message")
        }

        true
    }
}