We can reduce entire mio, async_std::net, and tokio::net down to just a single type! Here's how... 1/12
-
-
Since TcpStream::connect(addr) is a blocking function, we'll need it in an async flavor. Thanks to socket2 created by
@alex_crichton, async connect is easy to do: create a Socket, put it into non-blocking mode, call connect(addr), and wait until the socket becomes ready. 8/12pic.twitter.com/GSxUfLGHsP
Show this thread -
How do we "asyncify" methods like UdpSocket::send(buf)? There's an elegant solution invented by
@yoshuawuyts - methods Async::write_with(f) and Async::read_with(f) turn synchronous operation f into an asynchronous operation. 9/12pic.twitter.com/KwXmP0X0s8
Show this thread -
Async<T> is based on research done by
@yoshuawuyts, who managed to simplify mio and reactors down to a really small API with a straightforward implementation. 10/12Show this thread -
This is what an async TCP echo server looks like. (I'll explain the .unwrap().forget() part later) 11/12pic.twitter.com/OsBIrIGz0j
Show this thread -
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.