Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async fn in traits #413

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions example-service/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct Flags {
#[derive(Clone)]
struct HelloServer(SocketAddr);

#[tarpc::server]
impl World for HelloServer {
async fn hello(self, _: context::Context, name: String) -> String {
let sleep_time =
Expand All @@ -44,6 +43,10 @@ impl World for HelloServer {
}
}

async fn spawn(fut: impl Future<Output = ()> + Send + 'static) {
tokio::spawn(fut);
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let flags = Flags::parse();
Expand All @@ -66,7 +69,7 @@ async fn main() -> anyhow::Result<()> {
// the generated World trait.
.map(|channel| {
let server = HelloServer(channel.transport().peer_addr().unwrap());
channel.execute(server.serve())
channel.execute(server.serve()).for_each(spawn)
})
// Max 10 channels.
.buffer_unordered(10)
Expand Down
Loading
Loading