From 16a531e01198d60c5bdc6caddabc9125035ee35a Mon Sep 17 00:00:00 2001 From: Ivan Klass Date: Mon, 25 Nov 2024 18:23:31 +0100 Subject: [PATCH] trying to fix immediate exit of server --- .../scala/sttp/tapir/client/tests/HttpServer.scala | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/testserver/src/main/scala/sttp/tapir/client/tests/HttpServer.scala b/client/testserver/src/main/scala/sttp/tapir/client/tests/HttpServer.scala index 5b083ebf36..9fe56619bd 100644 --- a/client/testserver/src/main/scala/sttp/tapir/client/tests/HttpServer.scala +++ b/client/testserver/src/main/scala/sttp/tapir/client/tests/HttpServer.scala @@ -34,7 +34,7 @@ class HttpServer(port: Port) { private val logger = LoggerFactory.getLogger(getClass) - private var stopServer: IO[Unit] = _ + private val stopServer: Deferred[IO, Unit] = Deferred.unsafe[IO, Unit] // @@ -214,21 +214,19 @@ class HttpServer(port: Port) { // def start(): Unit = { - val (_, _stopServer) = EmberServerBuilder + EmberServerBuilder .default[IO] .withPort(ip4s.Port.fromInt(port).get) .withHttpWebSocketApp(app) .build - .allocated + .use(_ => stopServer.get) .unsafeRunSync() - stopServer = _stopServer - logger.info(s"Server on port $port started") } def close(): Unit = { - stopServer.unsafeRunSync() + stopServer.complete(()).unsafeRunSync() logger.info(s"Server on port $port stopped") } }