can't figure out how to spawn a future with async trait functions #5904
-
I have read about MVP part 2 send bounds and associated return types here However, I am still not able to get my sample to work in the context of what is being suggested. I am working on general purpose stock exchange connector that can establish and maintain connectivity to an arbitrary stock exchange using generics, traits, and data model that are all getting injected at the construction time and I have a code sample that I can't get to work. The general idea is that I have client and service socket, example only shows a service socket and before the stream goes into service loop it needs to pass a handshake routine which is exchange specific, hence injected as a generic trait, lets call it ProtocolInitHandler. I am unable to compile my code because it generates an error suggesting that my spawned future is not a Send and I am trying to understand how to make it send given materials in the MVP article. Actual project reference where I stumbled into the issue: links |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For now, I think the only way to work around it is the following: trait ProtocolInitHandler: Sync + Send + 'static {
fn login_sequence(&self) -> impl Future<Output = ()> + Send + '_;
}
impl ProtocolInitHandler for SvcProtocolInitHandler {
async fn login_sequence(&self) {
println!("login sequence do something");
}
} |
Beta Was this translation helpful? Give feedback.
For now, I think the only way to work around it is the following: