@@ -4,8 +4,6 @@ import jsonrpclib.CallId
44import jsonrpclib .fs2 ._
55import cats .effect ._
66import fs2 .io ._
7- import jsonrpclib .Endpoint
8- import cats .syntax .all ._
97import test ._ // smithy4s-generated package
108import jsonrpclib .smithy4sinterop .ClientStub
119import jsonrpclib .smithy4sinterop .ServerEndpoints
@@ -25,15 +23,21 @@ object ServerMain extends IOApp.Simple {
2523 def printErr (s : String ): IO [Unit ] = IO .consoleForIO.errorln(s)
2624
2725 def run : IO [Unit ] = {
28- val run = for {
29- channel <- FS2Channel [IO ](cancelTemplate = Some (cancelEndpoint))
30- testClient <- ClientStub .stream(TestClient , channel)
31- _ <- channel.withEndpointsStream(ServerEndpoints (new ServerImpl (testClient)))
32- _ <- fs2.Stream
33- .eval(IO .never) // running the server forever
34- .concurrently(stdin[IO ](512 ).through(lsp.decodeMessages).through(channel.inputOrBounce))
35- .concurrently(channel.output.through(lsp.encodeMessages).through(stdout[IO ]))
36- } yield {}
26+ val run =
27+ FS2Channel [IO ](cancelTemplate = Some (cancelEndpoint))
28+ .flatMap { channel =>
29+ ClientStub
30+ .stream(TestClient , channel)
31+ .flatMap { testClient =>
32+ channel.withEndpointsStream(ServerEndpoints (new ServerImpl (testClient)))
33+ }
34+ }
35+ .flatMap { channel =>
36+ fs2.Stream
37+ .eval(IO .never) // running the server forever
38+ .concurrently(stdin[IO ](512 ).through(lsp.decodeMessages).through(channel.inputOrBounce))
39+ .concurrently(channel.output.through(lsp.encodeMessages).through(stdout[IO ]))
40+ }
3741
3842 // Using errorln as stdout is used by the RPC channel
3943 printErr(" Starting server" ) >> run.compile.drain.guarantee(printErr(" Terminating server" ))
0 commit comments