Skip to content

Consider pre-packaging the "PreMaterialize" pattern (we could late optimize it too) #23895

@ktoso

Description

@ktoso

Pretty sure not many people can ad-hoc whip up this pattern to get a materialized value powered source to emit an entity yet it's very useful in practice:

example:

    val introspector = path("introspector") {
      concat(
        path(Segment / "inspect") { id 
          val refSource = Source.actorRef[ReplicatedIntrospector.Event](Int.MaxValue, OverflowStrategy.fail)
            .map(_.render)

          // TODO "pre-materialize pattern"
          val (ref, pub) =refSource.toMat(Sink.asPublisher(true))(Keep.both).run()
          val s = Source.fromPublisher(pub)
            .intersperse("\n")
            .map(ByteString(_))
          // end of "pre-materialize pattern"

          introspectorProxy.tell(ReplicatedIntrospector.Inspect, ref)
          
          complete(HttpResponse(entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, s)))
        }
      )
    }

I think we should be able to pre-build such a thing perhaps, document it as pre-materialize something and allow users to use it thanks to that rather than have them re-invent this pattern

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssues that the core team will likely not have time to work ont:stream

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions