smol-rs / blocking

A thread pool for isolating blocking I/O in async programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement AsyncBufRead for Unblock<T: BufRead>

Keruspe opened this issue · comments

Not sure how hard that would be, but this would make things like std::io::stdin().read_line() possible

Hmm, but Stdin does not implement BufRead, does it?

So I suppose we need to wrap it in BufReader in one of the following two ways:

  • BufReader::new(Unblock::new(std::io::stdin())).read_line()
  • Unblock::new(BufReader::new(std::io::stdin())).read_line()

I ended up doing

    let mut input = blocking::unblock(|| {
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).map(|_| input)
    })
    .await
    .unwrap();

this is fine enough, let's close this