Source

core hello world / hello_server.ml

Full commit
Yaron Minsky 5b67326 


Yaron Minsky 1fd795b 





Yaron Minsky 5b67326 
Yaron Minsky da7f04f 
Yaron Minsky 5b67326 


Yaron Minsky a86abec 
Yaron Minsky 5b67326 


Yaron Minsky a86abec 

Yaron Minsky 5b67326 



Yaron Minsky 1866b2a 
Yaron Minsky 5b67326 
Yaron Minsky a86abec 
Yaron Minsky 5b67326 
open Core.Std
open Async.Std

(* The implementation of the "hello" RPC.  The first argument is the environment
   the query executes against, which in this case is trivial.

   The RPC waits a 10th of a second before responding just to show how you do a
   query whose implementation blocks.
*)
let hello_impl () hello =
  Log.Global.info "received hello query (%s)" hello;
  Clock.after (sec 0.1)
  >>= fun () -> return (hello ^ " World!")

(* The list of RPC implementations supported by this server *)
let implementations =
  [ Rpc.Rpc.implement Hello_protocol.hello_rpc hello_impl ]

(* The command-line interface.  We use [async_basic] so that the command starts
   the async scheduler, and exits when the server stops.  *)
let command =
  Command.async_basic
    ~summary:"Hello World server"
    Command.Spec.(
      empty +> Common.port_arg ()
    )
    (fun port () -> Common.start_server ~env:() ~port ~implementations ())

let () = Command.run command