Let's introduce a new type Async<T> that "asyncifies" synchronous I/O types. For example, imagine you take a standard TcpStream and simply wrap it with Async to get an Async<TcpStream>! 4/12
-
Show this thread
-
You can think of Async<T> as a smart wrapper around a synchronous I/O type T. If T implements Read/Write, then Async<T> implements AsyncRead/AsyncWrite. 5/12pic.twitter.com/7HPfWSBj5U
1 reply 0 retweets 16 likesShow this thread -
Async<T> is not restricted to the standard networking types - it also seamlessly integrates with types from other libraries like socket2 or filedescriptor! 6/12
1 reply 0 retweets 7 likesShow this thread -
Async<T> also works with arbitrary file descriptors because its constructor accepts anything that implements AsRawFd (on Unix) or AsRawSocket (on Windows). 7/12pic.twitter.com/XlH0wSY8N6
1 reply 0 retweets 8 likesShow this thread -
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
1 reply 0 retweets 11 likesShow 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
1 reply 0 retweets 15 likesShow 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/121 reply 0 retweets 20 likesShow 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
2 replies 0 retweets 22 likesShow this thread -
And this is a simple HTTP GET request. 12/12pic.twitter.com/BlLI0Hozz0
2 replies 0 retweets 30 likesShow this thread -
Replying to @stjepang
And when are you going to update your smol crate for us to take a look? ;) https://crates.io/crates/smol
1 reply 0 retweets 1 like
Soon ;) It's fully implemented now and I'm just cleaning up, adding docs and examples and so on...
-
-
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
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.