Skip to content

Instantly share code, notes, and snippets.

@julien-truffaut
Last active October 26, 2015 12:08
Show Gist options
  • Save julien-truffaut/22f6453356671ff8aaca to your computer and use it in GitHub Desktop.
Save julien-truffaut/22f6453356671ff8aaca to your computer and use it in GitHub Desktop.
import remotely.{Type, Field, Protocol}
import remotely.codecs._
import remotely._
import remotely.transport.netty.NettyTransport
object protocol {
val definition = Protocol.empty
.codec[Int]
.specify1("factorial", Field.strict[Int]("in"), Type[Int])
}
@GenServer(protocol.definition)
abstract class FactorialServer
class FactorialServer0 extends FactorialServer {
val factorial: Int => Response[Int] = n =>
Response.now { (1 to n).product }
}
@GenClient(protocol.definition.signatures)
object FactorialClient
object ExampleServer extends App {
val address = new InetSocketAddress("localhost", 8080)
val service = new FactorialServer0
val env = service.environment
val startServer = env.serve(address)
val shutdown = startServer.run
}
object ExampleClient extends App {
val address = new InetSocketAddress("localhost", 8080)
val endpoint = NettyTransport.single(address).map(Endpoint.single).run
val res = evaluate(endpoint, Monitoring.consoleLogger())(FactorialClient.factorial(Remote.local(10))).apply(Context.empty)
res.map(println(_)).runAsync(_ => ())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment