生锈图案:等待溪流?
在以下常见用例中构建RUST程序的正确方法是什么?
用例,
我有一个可以查询服务器的流程。这很复杂:它查询了几台服务器和交通流。数据总量太大,无法进行内存。我想将该过程的结果表示为某种数据结构,每当可能从可能交织的流中出现新的令牌时,可以等待它们。
适当的Rust/Tokio数据结构是什么?
例如,在Python/JavaScript中,这可能是异步发生器。
fn query_data(...) -> ? {
// query servers
}
let stream = query_data(...);
async for token in stream {
// process token
}
What is the proper way to structure a Rust program for the following common use case?
Use Case
I have a process that queries servers for data. It's complicated: it queries several servers and interleaves streams from them. The total amount of data is too big for memory. I'd like to represent the result of that process as some kind of data structure that can be await-ed every time there is a new token from the possibly interleaved streams.
What is the proper Rust/tokio data structure to use?
As an example, in Python/JavaScript this could be an asynchronous generator.
fn query_data(...) -> ? {
// query servers
}
let stream = query_data(...);
async for token in stream {
// process token
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从
tokio-stream
扩展板条箱中使用流图
:You could use
StreamMap
from thetokio-stream
extension crate: