2 Star 1 Fork 0

蜗牛 / msgBus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

msg_bus

V0.0.2

介绍

msg_bus 异步事件消息处理总线,类似window 消息处理机制,通过注册消息,发送消息,消息响应。可以应用在多线程之间消息的传递。支持自定义消息数据类型,使用简单。使用示例如下。详细的例子参见 examples 目录。


#[async_trait]
impl MessageHandle<String> for MsgRunner{

    async fn handle_msg(&self, msg: MessageData<String>) ->std::result::Result<(),Box<dyn std::error::Error>>{
        match msg {
            MessageData::Data(s) => {
                println!("--- i am handle massage {}",s);
            },
            MessageData::None =>{
                println!("--- i am handle massage {}","None");
            }
        }
        Ok(())
    }

}
#[async_std::test]
async fn test_register() {
    let bus = MsgBus::<String>::new();

    let ru = MsgRunner{};
    bus.regist_msg(1, Box::new(ru)).await;
    let msg1 =Message{id:1,data:MessageData::Data("aaaaa".to_string())};

    bus.post_msg(msg1).await.unwrap();

    let msg2 =Message{id:1,data:MessageData::Data("bbb".to_string())};
    bus.post_msg(msg2).await.unwrap();
    // 等候下异步执行线程,输出结果;
    sleep(std::time::Duration::from_secs(5));
    println!("Done!");


}

欢迎大家共同完善,联系作者,请发邮件 2175318066@qq.com

MIT License Copyright (c) 2020 灰灰 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

rust 异步事件消息处理框架; 1:支持多线程中使用; 2:支持自定义 消息数据 类型; 展开 收起
Rust
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/21753/msgBus.git
git@gitee.com:21753/msgBus.git
21753
msgBus
msgBus
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891