3 releases

0.1.2 Oct 20, 2021
0.1.1 Oct 20, 2021
0.1.0 Oct 20, 2021

#7 in #socket

MIT license

11KB
160 lines

async-socket

This crate implements a general-purpose asynchronous socket.

The Socket implements AsyncRead, AsyncWrite, Stream and Clone traits and thus mimics the functionality and the behaviour of the TcpStream and UnixStream objects. These propertis makes it a perfect tool for testing network activities and events.

Documentation Source

Usage

Example:

use async_socket::Socket;
use async_std::task::spawn;
use futures::io::AsyncWriteExt;
use futures::stream::StreamExt;

async fn example() {
    let mut stream = Socket::default();
    let mut writer = stream.clone();

    spawn(async move {
        writer.write(b"Hello").await.unwrap();
    });

    while let Some(bytes) = stream.next().await {
        // ...
    }
}

License: MIT

Dependencies

~0.6–0.8MB
~15K SLoC