Skip to content

Commit

Permalink
trying to fix immediate exit of server
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-klass committed Nov 25, 2024
1 parent 850c85f commit 16a531e
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]

//

Expand Down Expand Up @@ -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")
}
}

0 comments on commit 16a531e

Please sign in to comment.