Async stream¶
Category: Async · Status: stub · Lessons: chapter 06, Async (planned)
One line: An asynchronous iterator: a sequence whose items arrive over time, each one awaited in turn.
Also called: Stream, async generator, AsyncIterator, Sink.
How it connects¶
flowchart LR
n_async_stream["Async stream"]
n_future_and_promise["Future and promise"]
n_reactive_programming["Reactive programming"]
n_async_stream -->|uses| n_future_and_promise
n_reactive_programming -->|uses| n_async_stream
classDef center stroke-width:3px
class n_async_stream center
classDef outside stroke-dasharray: 4 3
class n_future_and_promise,n_reactive_programming outside
- Is built on: Future and promise
- Is used by: Reactive programming
In each language¶
| Rust | no stable trait: std's AsyncIterator ↗ is a nightly-only experimental API |
| Java | Flow.Publisher ↗, with the subscriber requesting items |
| Python | asynchronous generators ↗, consumed with async for ↗ |
| C# | IAsyncEnumerable<T> ↗, consumed with await foreach ↗ |
| JavaScript | async function* ↗ generators, consumed with for await...of ↗ |
| Kotlin | Flow ↗: a cold flow is lazy and runs anew for each collector, a hot flow shares its values with all collectors |
| Swift | AsyncSequence ↗, iterated with for await; an AsyncStream ↗ builds one from a closure |
Where to read more¶
- In the books: C++ Reactive Programming, Praseed Pai, Peter Abraham — ch. 6, 'Introduction to Event Stream Programming Using C++'
- In the books: Concurrency in C# Cookbook, Stephen Cleary — ch. 3, 'Asynchronous Streams'
- In the books: asyncio Recipes, Mohamed Mustapha Tahrioui — ch. 4, 'Working with Async Generators'
- In the books: Kotlin Coroutines by Tutorials, Filip Babić, Nishant Srivastava — ch. 14, 'Beginning with Coroutines Flow'
- In the books: Effective Concurrency in Go, Burak Serdar — ch. 8, 'Handling Requests Concurrently' → 'Streaming data'
- In the books: Learning Concurrent Programming in Scala, Aleksandar Prokopec — ch. 10, 'Reactors' → 'Event streams'
- Notes: sink - rust - futures::sink::Sink ↗