Actix错误“使用Self :: Context :: notify()代替直接使用地址”是什么意思?

时间:2018-12-25 15:06:30

标签: rust rust-actix

我编辑了Actix example

extern crate actix;
extern crate futures;
extern crate tokio;

use std::{thread, time};

use actix::prelude::*;
use futures::future::*;
use futures::Future;
use std::time::SystemTime;

/// Define `Ping` message
struct Ping(usize);

impl Message for Ping {
    type Result = usize;
}

/// Actor
struct MyActor {
    count: usize,
}

/// Declare actor and its context
impl Actor for MyActor {
    type Context = Context<Self>;
}

/// Handler for `Ping` message
impl Handler<Ping> for MyActor {
    type Result = usize;

    fn handle(&mut self, msg: Ping, _: &mut Context<Self>) -> Self::Result {
        self.count += msg.0;
        self.count
    }
}

fn main() {
    // start system, this is required step
    System::run(|| {
        // start new actor
        let addr = MyActor { count: 10 }.start();

        let start = SystemTime::now();

        // send message and get future for result
        let res = join_all((1..1000).into_iter().map(move |x| addr.send(Ping(x))));

        // handle() returns tokio handle
        tokio::spawn(
            res.map(move |_res| {
                let end = SystemTime::now();
                let difference = end
                    .duration_since(start)
                    .expect("SystemTime::duration_since failed");

                println!("Time taken: {:?}", difference);

                // stop system and exit
                System::current().stop();
            })
            .map_err(|_| ()),
        );
    });
}

运行代码let res = join_all((1..1000).into_iter().map(move |x| addr.send(Ping(x))));时出现错误。直到256(在mailbox.rs中定义为MAX_SYNC_POLLS)的数字上都不会发生这种情况,但是如果我将其设置为1000,则会发生这种情况。当我阅读代码时,它实际上是一个debugassert语句;它与--release标志一起运行。

  

线程“主”对“使用Self :: Context :: notify()而不是   直接使用地址”,src / mailbox.rs:103:17

这是什么紧急消息?如果改用Context::notify()会提高性能吗?如果可以,该如何使用?

0 个答案:

没有答案