-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
If you want to wait for a certain state, it would be neat to be able to not just map but also filter and filter_map on a watcher.
E.g. when waiting for a direct connection, this is currently only possible by manually looping through the stream:
let on_connected = |ep: Endpoint, conn: Connection| async move {
let Ok(id) = conn.remote_node_id() else {
return Err(io::Error::other("unable to get node id"));
};
let Some(watcher) = ep.conn_type(id) else {
return Err(io::Error::other("unable to get conn_type watcher"));
};
let mut stream = watcher.stream();
while let Some(status) = stream.next().await {
if let ConnectionType::Direct { .. } = status {
return Ok(());
}
}
Err(io::Error::other("connection closed before becoming direct"))
};Having filter_map would simplify this to:
let on_connected = |ep: Endpoint, conn: Connection| async move {
let Ok(id) = conn.remote_node_id() else {
return Err(io::Error::other("unable to get node id"));
};
let Some(watcher) = ep.conn_type(id) else {
return Err(io::Error::other("unable to get conn_type watcher"));
};
watcher.filter(|t| t == ConnectionType::Direct).initialized().await;
};Metadata
Metadata
Assignees
Labels
No labels