Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit a142bf6

Browse files
authored
Fix execution context regression (#52)
1 parent a07dee3 commit a142bf6

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fix implicit execution context regression
6+
37
## 1.1.0 (2020-04-18)
48

59
- Fix implicits for HTTP/2 API

core/src/main/scala/fr/davit/akka/http/metrics/core/scaladsl/server/HttpMetricsRoute.scala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,22 @@ final class HttpMetricsRoute private (route: Route) extends HttpMetricsDirective
5656
executionContext: ExecutionContextExecutor = null,
5757
rejectionHandler: RejectionHandler = RejectionHandler.default,
5858
exceptionHandler: ExceptionHandler = null
59-
): Flow[HttpRequest, HttpResponse, NotUsed] =
60-
Flow[HttpRequest]
61-
.mapAsync(1)(recordMetricsAsync(metricsHandler))
62-
.watchTermination() {
63-
case (mat, completion) =>
64-
// every connection materializes a stream
65-
metricsHandler.onConnection(completion)
66-
mat
67-
}
59+
): Flow[HttpRequest, HttpResponse, NotUsed] = {
60+
val effectiveEC = if (executionContext ne null) executionContext else materializer.executionContext
61+
62+
{
63+
// override the execution context passed as parameter
64+
implicit val executionContext: ExecutionContextExecutor = effectiveEC
65+
Flow[HttpRequest]
66+
.mapAsync(1)(recordMetricsAsync(metricsHandler))
67+
.watchTermination() {
68+
case (mat, completion) =>
69+
// every connection materializes a stream.
70+
metricsHandler.onConnection(completion)
71+
mat
72+
}
73+
}
74+
}
6875

6976
def recordMetricsAsync(metricsHandler: HttpMetricsHandler)(
7077
implicit

0 commit comments

Comments
 (0)