+Core and Async Hello World
A simple hello-world project for Core. The intent is to show you how
to get started building OCaml projects using OPAM, Core and
-OCamlbuild. To use this, first get OPAM, and install the "core"
-package. Also, it's probably doing this:
- $ opam switch ocaml-4.00.1+short-types
+Before getting started with this code, you should follow the
+instructions in the PREREQUISITES.
-to get better error messages from the compiler when using Core. (As
-of 4.01, this compiler variant should be obsolete.)
-You can build all the pieces of this project by running:
+Once that's done, you can build all the pieces of this project by
+This is a very simple exercise that shows you how to make a basic
+command-line application using Core's `Command` module.
This executable is `hello_world.native` (or `hello_world.byte`), and
here's an example of it in action.
let shutdown_rpc = Rpc.Rpc.create
(* First, we build the implementations *)
let publish_impl (dir,_) msg =
+ Log.Global.sexp ~level:`Debug msg
return (Directory.publish dir msg)
let subscribe_impl (dir,_) topic ~aborted =
- ocamlbuild -use-ocamlfind $TARGET -cflags "-w @A-4-33-23" -cflags -short-paths
+ocamlbuild -j 4 -use-ocamlfind -cflags "-w @A-4-33-23" -cflags -short-paths $*
let start_server ~env ?(stop=Deferred.never ()) ~implementations ~port () =
- Log.Global.info "
starting server on %d" port;
+ Log.Global.info "tarting server on %d" port;
~on_unknown_rpc:(`Call (fun ~rpc_tag ~version ->
Log.Global.info "Unexpected RPC, tag %s, version %d" rpc_tag version))
- Log.Global.info "About to start TCP server";
~on_handler_error:(`Call (fun _ exn -> Log.Global.sexp exn Exn.sexp_of_t))
- Log.Global.info "
TCP server started, waiting for close";
+ Log.Global.info "erver started, waiting for close";
[ (stop >>= fun () -> Tcp.Server.close server)
; Tcp.Server.close_finished server ]
query whose implementation blocks.
let hello_impl () hello =
+ Log.Global.info "received hello query (%s)" hello;
>>= fun () -> return (hello ^ " World!")