Add small patterns library

integrate-threads-example
Florian Gilcher 5 years ago
parent eadd3ed1f6
commit 6c7922a404
No known key found for this signature in database
GPG Key ID: E7B51D33F8EBF61B

@ -17,6 +17,7 @@
- [Proper Shutdown](./patterns/proper-shutdown.md)
- [Background Tasks](./patterns/background-tasks.md)
- [Testing](./patterns/testing.md)
- [Collected Small Patterns](./patters/small-patterns.md)
- [Security practices](./security/index.md)
- [Security disclosures and policy](./security/policy.md)
- [Glossary](./glossary.md)

@ -1 +1,5 @@
# Async Patterns
# Patterns
This section documents small, useful patterns.
It is intended to be read at a glance, allowing you to get back when you have a problem.

@ -0,0 +1,18 @@
# Small Patterns
A collection of small, useful patterns.
<!-- toc -->
## Splitting streams
`async-std` doesn't provide a `split()` method on `io` handles. Instead, splitting a stream into a read and write half can be done like this:
```rust
use async_std::io;
async fn echo(stream: io::TcpStream) {
let (reader, writer) = &mut (&stream, &stream);
io::copy(reader, writer).await?;
}
```
Loading…
Cancel
Save