Motivation
Currently, pekko provides Sink.lazyInit for lazily creating a sink based on the first element, and Source.lazySource/Source.lazyFutureSource for lazy source creation. However, there is no equivalent operator for Flow — the ability to lazily create a flow based on the first element that passes through it.
This is useful when:
- The flow's behavior depends on properties of the first element (e.g., detecting format/encoding from the first message)
- Expensive resources should only be initialized when data actually starts flowing
- The flow factory is asynchronous (e.g., needs to query a service before deciding how to process elements)
Proposed Enhancement
Add a Flow.lazyInitAsync operator that:
- Accepts a factory function
(firstElement: T) => Future[Flow[T, U, M]]
- On the first element, invokes the factory asynchronously
- Materializes the returned flow and feeds all elements (including the first) through it
- Returns the materialized value of the lazily created flow
References
This operator was implemented in the Akka.NET project: akkadotnet/akka.net#5476
Motivation
Currently, pekko provides
Sink.lazyInitfor lazily creating a sink based on the first element, andSource.lazySource/Source.lazyFutureSourcefor lazy source creation. However, there is no equivalent operator forFlow— the ability to lazily create a flow based on the first element that passes through it.This is useful when:
Proposed Enhancement
Add a
Flow.lazyInitAsyncoperator that:(firstElement: T) => Future[Flow[T, U, M]]References
This operator was implemented in the Akka.NET project: akkadotnet/akka.net#5476