Skip to content

Compile failed when tokio::sync::mpsc::Sender send format!() String #1692

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

Closed
frostRed opened this issue Oct 26, 2019 · 1 comment
Closed

Comments

@frostRed
Copy link

frostRed commented Oct 26, 2019

Version

tokio-0.2-alpha.6

rust nightly-20191024

Platform

Manjaro Linux AMD64

Description

Compile failed when tokio::sync::mpsc::Sender send format!() String.

I am not sure if this is a compiler bug or a problem with tokio.

use tokio::sync::mpsc::{Sender, channel};
use tokio::runtime::{self};
use futures::{FutureExt, TryFutureExt, StreamExt};
use std::thread::sleep;
use std::time::Duration;

fn main() {
    let runtime = runtime::Builder::new()
        .core_threads(2)
        .name_prefix("tokio-")
        .build()
        .map_err(|e| panic!("New Runtime failed: {:?}", e))
        .expect("tokio runtime error");

    let (tx, rx) = channel::<String>(2);
    let e = runtime.executor();
    e.spawn(t(tx.clone()));

    e.spawn(async move {
        let mut rx = rx;
        while let Some(s) = rx.next().await{
            println!("{}", s);
        }
    });

    sleep(Duration::from_secs(10));
}

async fn t(tx: Sender<String>) {
    let mut t = tx.clone();
    for i in 0..5u8 {
        let s = format!("{}", i);
        t.send(s).map_err(|_| ()).map(|_| ()).await;

// can't compile
//        t.send(format!("{}", i)).map_err(|_| ()).map(|_| ()).await;
    }
}
@sinkuu
Copy link
Contributor

sinkuu commented Oct 30, 2019

This is a compiler bug. rust-lang/rust#64960

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants