结论:直接调用b.poll_read即可
描述的有点乱,请见谅,如果需要额外说明,请留言 问题如代码:
struct A{
b: B
}
impl tokio::io::AsyncRead for B {...略...}
impl tokio::io::AsyncRead for A {
# 如何调用B的AsyncRead.使得当B有数据时,可以唤醒A的AsyncRead?
}
目前我的做法是通过额外的异步任务+通道实现,伪代码如下,请问有更合适的办法吗?能否在唤醒B的时候,直接唤醒A?
async fn middle() {
let waker = Option<Waker>;
select! {
read_buf(b) => {
send_channel(data);
waker.wake()
}
recv_channel(waker_tmp) => {
let waker = Some(waker_tmp);
}
}
}
1
共 6 条评论, 1 页
评论区
写评论抱歉,直接调用b的poll_read即可,之前是因为我自己实现,没有唤醒,才导致程序的不正常!
--
👇
songzhi: 还有一个ready!宏
--
👇
songzhi: 不是有asyncreadext吗?
--
👇
fengqi2019: tokio::io::AsyncRead的fn poll_read不是异步的,没法直接await
--
👇
songzhi:
b.read(&mut buf).await
调用ready!,若结果是Pending,则后续无法再次唤醒该异步任务
--
👇
songzhi: 还有一个ready!宏
--
👇
songzhi: 不是有asyncreadext吗?
--
👇
fengqi2019: tokio::io::AsyncRead的fn poll_read不是异步的,没法直接await
--
👇
songzhi:
b.read(&mut buf).await
还有一个ready!宏
--
👇
songzhi: 不是有asyncreadext吗?
--
👇
fengqi2019: tokio::io::AsyncRead的fn poll_read不是异步的,没法直接await
--
👇
songzhi:
b.read(&mut buf).await
不是有asyncreadext吗?
--
👇
fengqi2019: tokio::io::AsyncRead的fn poll_read不是异步的,没法直接await
--
👇
songzhi:
b.read(&mut buf).await
tokio::io::AsyncRead的fn poll_read不是异步的,没法直接await
--
👇
songzhi:
b.read(&mut buf).await
b.read(&mut buf).await