[][src]Crate tokio_stdin

NOTE: This library is no longer necessary. As of tokio 0.1.6, it is now possible to read from stdin without the overhead of spawning a separate thread with the tokio::io::stdin function.

Read from stdin as a Tokio stream by spawning a separate thread.

extern crate futures;
extern crate tokio_stdin;

fn main() {
    use futures::Stream;

    tokio_stdin::spawn_stdin_stream_unbounded().wait();
}

As far as I know, this is currently the recommended way to do this. On Dec 29, 2016, alexcrichton commented:

In general for small CLI tools and such what you probably want to do is to use channels to communicate to foreign threads. You can have a thread per stdin/stdout/stderr with a futures::sync::mpsc that the main thread communicates with.

This crate locks stdin while it's running, so trying to read from stdin in another part of your code will probably cause a deadlock.

See the count_keys example for a simple use of this.

Functions

spawn_stdin_stream_bounded

Spawn a new thread that reads from stdin and passes messages back using a bounded channel.

spawn_stdin_stream_unbounded

Spawn a new thread that reads from stdin and passes messages back using an unbounded channel.