Skip to content

Simplify lazySingle and lazyFuture via operator composition#2731

Draft
pjfanning wants to merge 3 commits intoapache:mainfrom
pjfanning:copilot/copy-pull-31735-from-akka-core
Draft

Simplify lazySingle and lazyFuture via operator composition#2731
pjfanning wants to merge 3 commits intoapache:mainfrom
pjfanning:copilot/copy-pull-31735-from-akka-core

Conversation

@pjfanning
Copy link
Member

Port of akka/akka-core#31735. Replaces custom LazySingleSource and LazyFutureSource graph stages with equivalent compositions of existing operators, removing ~120 lines of bespoke stage code.

part of #2730

Changes

  • scaladsl/Source.scala
    • lazySingle: fromGraph(new LazySingleSource(create))single(()).map(_ => create()).withAttributes(DefaultAttributes.lazySingle)
    • lazyFuture: fromGraph(new LazyFutureSource(create))single(()).mapAsyncUnordered(1)(_ => create()).withAttributes(DefaultAttributes.lazyFuture)
  • impl/Stages.scala: Added DefaultAttributes.lazySingle and DefaultAttributes.lazyFuture; removed now-unused lazySingleSource and lazyFutureSource
  • Deleted: impl/fusing/LazySingleSource.scala, impl/fusing/LazyFutureSource.scala

mapAsyncUnordered(1) is used directly for lazyFuture since mapAsync(1) is internally optimised to unordered anyway.

Copilot AI and others added 2 commits March 16, 2026 00:01
…m graph stages

Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
@pjfanning pjfanning marked this pull request as draft March 16, 2026 08:25
… attribute names

Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
@pjfanning
Copy link
Member Author

I'll leave this as Draft to allow discussion about whether the customised code that this PR removes is actually better than this change.

@pjfanning
Copy link
Member Author

@He-Pin wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants