SaneCppAsyncStreams.h is a library that reads and writes data concurrently from async sources to destinations.
Dependencies
- Dependencies: (none)
- All dependencies: (none)
Features
This is the list of implemented objects stream types
| Async Stream | Description |
|---|---|
| AsyncReadableStream | SC::AsyncReadableStream |
| AsyncWritableStream | SC::AsyncWritableStream |
| AsyncDuplexStream | SC::AsyncDuplexStream |
| AsyncTransformStream | SC::AsyncTransformStream |
| AsyncPipeline | SC::AsyncPipeline |
| AsyncReadableFileStream | SC::AsyncReadableFileStream |
| AsyncWritableFileStream | SC::AsyncWritableFileStream |
| AsyncReadableSocketStream | SC::AsyncReadableSocketStream |
| AsyncWritableSocketStream | SC::AsyncWritableSocketStream |
Details
Status
MVP
A basic set of stream to pipe Sockets and Files (Pipes included) has been implemented.
Also basic transform streams (ZLib based) have been implemented.
It's possible that its API will evolve a little bit to be less verbose and there is also lack of nice examples, aside from the tests.
Implementation
Async Streams support reading from an async source and placing such reads in a bounded request queue that will pause the stream when it becomes full or when there are no available buffers.
Data is pushed downstream to listeners of data events, that are either transform streams or writers streams.
Writers will eventually emit a drain event to signal that they can write more data.
Such event can be used to resume the readable streams that may have been paused.
AsyncPipeline doesn't use the drain event but it just resumes readable streams after every successful write.
This works because the Readable will pause when running out of buffers, allowing them to resume when a new one is made available.
ReadableFileStream and WritableFileStream now also support initialization directly from SC::PipeDescriptor (in addition to SC::FileDescriptor).
This makes named pipes (see File) compose directly with Async Streams without manual extraction of readPipe / writePipe.
Memory allocation
Async streams do not allocate any memory, but use caller provided buffers for handling data and request queues.
Videos
This is the list of videos that have been recorded showing some of the internal thoughts that have been going into this library:
- Ep.28 - C++ Async Readable Streams
- Ep.29 - C++ Async Writable Streams
- Ep.30 - C++ Async Streams Pipeline
- Ep.31 - C++ Async Socket Streams
- Ep.32 - C++ Async Transform Streams - Part 1
- Ep.33 - C++ Async Transform Streams - Part 2
- Ep.34 - C++ Async Transform Streams - Part 3
Blog
Some relevant blog posts are:
- November 2024 Update
- December 2024 Update
- January 2025 Update
- August 2025 Update
- November 2025 Update
- December 2025 Update
- January 2026 Update
- March 2026 Update
Roadmap
Usable features:
- Pipeline pause
- Pipeline resume
Complete Features:
- writev style asyncWrite
💡 Unplanned Features:
- Object Mode
- readable + read mode
Statistics
| Type | Lines Of Code | Comments | Sum |
|---|---|---|---|
| Headers | 786 | 441 | 1227 |
| Sources | 1886 | 278 | 2164 |
| Sum | 2672 | 719 | 3391 |