Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsoni committed Mar 25, 2020
1 parent 0f5ef66 commit e39c8f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,27 @@ let print_param =
put "/hello/:name" (fun req ->
`String ("Hello " ^ param req "name") |> respond')
let streaming =
let open Lwt.Infix in
get "/hello/stream" (fun _req ->
(* [create_stream] returns a push function that can be used to
push new content onto the stream. [f] is function that
expects to receive a promise that gets resolved when the user
decides that they have pushed all their content onto the stream.
When the promise forwarded to [f] gets resolved, the stream will be
closed. *)
let f, push = App.create_stream () in
let timers =
List.map
(fun t ->
Lwt_unix.sleep t
>|= fun () -> push (Printf.sprintf "Hello after %f seconds\n" t))
[1.; 2.; 3.]
in
f (Lwt.join timers))
let default =
not_found (fun req ->
not_found (fun _req ->
`Json Ezjsonm.(dict [("message", string "Route not found")]) |> respond')
let print_person =
Expand All @@ -93,7 +112,9 @@ let print_person =
in
`Json (person |> json_of_person) |> respond')
let _ = App.empty |> print_param |> print_person |> default |> App.run_command
let _ =
App.empty |> print_param |> print_person |> streaming |> default
|> App.run_command
```

compile and run with:
Expand Down
6 changes: 6 additions & 0 deletions examples/hello_world.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ let print_param =
let streaming =
let open Lwt.Infix in
get "/hello/stream" (fun _req ->
(* [create_stream] returns a push function that can be used to
push new content onto the stream. [f] is function that
expects to receive a promise that gets resolved when the user
decides that they have pushed all their content onto the stream.
When the promise forwarded to [f] gets resolved, the stream will be
closed. *)
let f, push = App.create_stream () in
let timers =
List.map
Expand Down

0 comments on commit e39c8f2

Please sign in to comment.