I'm following the documentation for tokio::runtime::Runtime and trying to adapt it to create a TcpStream that serves as a client to a remote server. I'd like to have the support of a thread pool because my applications may have hundreds of clients each connecting to a remote server.
The problem is when I adapt the example to use TcpStream instead of a TcpListener, it seems to have a problem with the return type:
let runtime = runtime::Builder::new().threaded_scheduler().build()?;
let ret = runtime.block_on(async {
let mut listener = TcpStream::connect("127.0.0.1:8080").await?;
});
It fails with the error:
the
?operator can only be used in an async block that returnsResultorOption(or another type that implementsstd::ops::Try) the traitstd::ops::Tryis not implemented for()required bystd::ops::Try::from_errorrustc(E0277)
I believe this comes from .await? which is used with bind() and accept(). So is the example outdated or am I missing something with accept()?