Channel is a low-level streaming primitive that forms the foundation of both Stream and Sink. It represents a nexus of I/O operations supporting both reading and writing.
Channels are the foundational building blocks of Effect’s streaming capabilities. Most users should use Stream and Sink instead, but Channel is useful for advanced use cases and creating new streaming operators.
Type Parameters
AChannel has seven type parameters:
OutElem: Type of output elementsInElem: Type of input elements (contravariant)OutErr: Type of output errorsInErr: Type of input errors (contravariant)OutDone: Type of output completion valueInDone: Type of input completion value (contravariant)Env: Context requirements
Basic Channels
Creating Channels
Composing Channels
Channel Operations
Mapping
Transforming Inputs
Error Handling
Folding
Merging and Concatenation
Concatenation
Merging
Resource Management
Acquire-Release
Finalizers
Reading and Writing
Reading
Writing
Buffering
Interruption
Channel to Stream/Sink
Advanced Patterns
Custom Merging Strategy
Embedding Input
Collecting Output
Integration with Effect
Performance Considerations
- Use channels directly only for advanced use cases - Prefer
StreamandSinkfor most scenarios - Chunk-based operations - Work with chunks rather than individual elements for better performance
- Resource management - Always use proper acquire-release patterns
- Buffering - Use buffering to improve throughput when dealing with bursty data