多个生产者和多个读者频道?
是否可以在Rust中创建一个在Rust中的通道,并在Rust中读取数量的发送和读取?基本上,我想将几个任务发送到频道作为初始化的形式,然后以并行方式开始执行任务。但是问题是任务本身有时可以创建并将任务发送到频道。当所有任务都消耗时,渠道应关闭。我认为频道实现最适合这种特殊情况,但是RUST似乎没有多源 +多消费者频道实现。或者,如果我试图实施我不应该和 /或不可能实施的东西,也欢迎提供全新的范式的建议。
谢谢你!
Is it possible to create a channel in Rust with a non-determinate number of sends and reads in rust? Basically I want to send couple tasks up to channel as a form of an initialization and then start executing the tasks in a parallel way. But the problem is tasks themselves sometimes can create and send the tasks up to channel. The channel should close when all tasks have been consumed. I thought channel implementation would suit best for this particular case but Rust doesn't seem to have a multiproducer + multiconsumer channel implementation. Or suggestions of a completely new paradigm would also be welcome if I am trying to implement something I am not supposed to and / or is not possible.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
std :: Sync :: MPSC
或crossbeam_channel
正式更好,更快,但需要拉出外部板条箱。std :: Sync :: mpsc
的文档:https://doc.rust-lust-lang.org/nightly/ std/sync/mpsc/index.html
crossbeam_channel的文档
:You may use either
std::sync::mpsc
orcrossbeam_channel
the formal is better and faster but requires pulling an external crate.Documentation of
std::sync::mpsc
:https://doc.rust-lang.org/nightly/std/sync/mpsc/index.html
Documentation of
crossbeam_channel
:https://docs.rs/crossbeam-channel/latest/crossbeam_channel/