jrudolph commented on issue #638:
URL: https://github.com/apache/pekko-http/issues/638#issuecomment-2556464031

   My idea was to try to invert the flow using a joinable ServerTerminator 
implementation like this:
   
   ```scala
   private class JoinableServerTermination extends ServerTerminator {
     private val terminationInitiated = Promise[Done]()
     private val terminationCompleted = new 
AtomicReference[Future[Http.HttpTerminated]](Future.successful(Http.HttpServerTerminated))
   
     def onTerminationInitiated(f: () => Future[Http.HttpTerminated]): Unit = {
       val promise = Promise[Http.HttpTerminated]()
   
       def chain(f: Future[Http.HttpTerminated]): Unit = {
         val p = terminationCompleted.get()
         if (!terminationCompleted.compareAndSet(p,p.flatMap(_ => 
promise.future)(ExecutionContexts.parasitic)))
           chain(f)
       }
   
       chain(promise.future)
       terminationInitiated.future.foreach { _ => promise.completeWith(f())
       }(ExecutionContexts.parasitic)
     }
   
     override def terminate(deadline: FiniteDuration)(implicit ex: 
ExecutionContext): Future[Http.HttpTerminated] = {
       terminationInitiated.tryComplete(Success(Done))
       terminationCompleted.get()
     }
   }
   ```
   
   The next question would be how to get it into 
`mapAsync(...)(handleUpgradeRequest)` which could work something like this:
   
   ```scala
   val http1: HttpImplementation =
           Flow.lazyFlow { () =>
             val termination = new JoinableServerTermination
             Flow[HttpRequest]
             .mapAsync(settings.pipeliningLimit)(handleUpgradeRequests(handler, 
settings, log, termination))
               .mapMaterializedValue(_ => termination)
           }
           .joinMat(GracefulTerminatorStage(system, 
settings).atop(http.serverLayer(settings, log = log)))( /* join http1 
termination here */)
   ```
   
   In `handleUpgradeRequest` the ServerTerminator coming out of 
`Http2.serverStack` would have to be joined to the joinable termination.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org
For additional commands, e-mail: notifications-h...@pekko.apache.org

Reply via email to