advance/async/multi-futures-simultaneous #838
Replies: 19 comments 12 replies
-
跟 Unpin 和 FusedFuture 进行交互这部分好像有点问题,准确的说来自变量名/路径的
|
Beta Was this translation helpful? Give feedback.
-
future 的set方法是哪个trait为其添加的啊?它的行为是会中断旧的future,来运行新的future吗? |
Beta Was this translation helpful? Give feedback.
-
我有个疑惑,关于default和complete分支的,如果所有future都执行完了,不就是所有future都不是ready状态,此时不就是同时满足default和complete吗? |
Beta Was this translation helpful? Give feedback.
-
这里的例子最好把 mut interval_timer: impl Stream<Item = ()> + FusedStream + Unpin 解释一下, 要不然很难理解为什么在 interval_timer 连续不断产生值的情况下, select! 还能运行下一个, 而不是一直在运行第一条. |
Beta Was this translation helpful? Give feedback.
-
FusedFuture的原因跟上面类似,当 Future 一旦完成后,那 select 就不能再对其进行轮询使用。Fuse意味着熔断,相当于 Future 一旦完成,再次调用poll会直接返回Poll::Pending 这里应该是直接放回Poll::Ready(None) 吧。不然pending的话,下次还是会被调用 |
Beta Was this translation helpful? Give feedback.
-
已阵亡在 |
Beta Was this translation helpful? Give feedback.
-
这部分也太枯燥了。。。 |
Beta Was this translation helpful? Give feedback.
-
futures包给出的样例代码是这样的: use futures::future::join_all;
async fn foo(i: u32) -> u32 { i }
let futures = vec![foo(1), foo(2), foo(3)];
assert_eq!(join_all(futures).await, [1, 2, 3]); |
Beta Was this translation helpful? Give feedback.
-
如果fused看不懂,建议看futures包的原始文档 |
Beta Was this translation helpful? Give feedback.
-
Futures包的这个select!宏绝对是参考了GO的select语句设计的 |
Beta Was this translation helpful? Give feedback.
-
err_info -> err_into |
Beta Was this translation helpful? Give feedback.
-
我大抵是学不会了,横竖睡不着,坐起来点了一支烟,没由来的悲伤,黯然看着 |
Beta Was this translation helpful? Give feedback.
-
如何修改代码才能走让select!执行default分支 |
Beta Was this translation helpful? Give feedback.
-
这怎么写的出相应的代码来😐 |
Beta Was this translation helpful? Give feedback.
-
放在js里大概就这个感觉吧: |
Beta Was this translation helpful? Give feedback.
-
这里写错了把,以下是chatGPT的回答:
具体来说,
use futures::future::{FutureExt, FusedFuture};
use futures::pin_mut;
use futures::task::Poll;
async fn example() -> i32 {
42
}
fn main() {
let future = example().fuse();
pin_mut!(future);
assert!(!future.is_terminated());
let poll_result = future.poll_unpin(&mut futures::task::noop_waker_ref());
assert!(matches!(poll_result, Poll::Ready(42)));
assert!(future.is_terminated());
} 在这个例子中, |
Beta Was this translation helpful? Give feedback.
-
这句话不是很理解:【default 分支,若没有任何 Future 或 Stream 处于 Ready 状态, 则该分支会被立即执行】
有没有可能future::pending()函数在骗我?(文档写的是...never finishes) |
Beta Was this translation helpful? Give feedback.
-
应该是参考了Golang的 for select. |
Beta Was this translation helpful? Give feedback.
-
advance/async/multi-futures-simultaneous
https://course.rs/advance/async/multi-futures-simultaneous.html
Beta Was this translation helpful? Give feedback.
All reactions