Skip to content

Commit 703e25a

Browse files
committed
Convert for-comp to flatMap
1 parent 67c49a5 commit 703e25a

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

modules/examples/smithyServer/src/main/scala/examples/smithy/server/ServerMain.scala

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import jsonrpclib.CallId
44
import jsonrpclib.fs2._
55
import cats.effect._
66
import fs2.io._
7-
import jsonrpclib.Endpoint
8-
import cats.syntax.all._
97
import test._ // smithy4s-generated package
108
import jsonrpclib.smithy4sinterop.ClientStub
119
import 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"))

modules/fs2/src/main/scala/jsonrpclib/fs2/lsp.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ object lsp {
138138
}
139139
continue = false
140140
} else {
141-
bb.put(byte)
141+
val _ = bb.put(byte)
142142
}
143143
}
144144
if (newState != null) {

0 commit comments

Comments
 (0)