Skip to content

Commit

Permalink
use eio with lwt_eio
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed Mar 23, 2024
1 parent b7c0ce6 commit b3e58b9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ let server () =
req |> render ~default [ (text_html, main) ]
in

Eio_main.run @@ fun env ->
Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ ->
Lwt_eio.run_lwt @@ fun () ->
Httpq.Server.start_server ~port ~error_handler Router.handler @@ fun () ->
Migration.verify_migration_status ();%lwt
Logq.info (fun m -> m "Listening on 127.0.0.1:%d" port);
Expand Down
3 changes: 3 additions & 0 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
camlimages.xpm
cstruct
curl.lwt
eio
eio_main
fpath
httpq
jingoo
lambdasoup
logq
lwt
lwt_eio
lwt.unix
mirage-crypto-rng
mirage-crypto-rng.lwt
Expand Down
2 changes: 1 addition & 1 deletion lib_httpq/bare_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let start_server port k callback =
Cohttp_lwt_unix.Server.make_response_action ~callback ()
|> Cohttp_lwt_unix.Server.create ~mode:(`TCP (`Port port))
in
Lwt.pick [ server; (k >>= fun () -> Lwt.task () |> fst) ] |> Lwt_main.run
Lwt.pick [ server; (k >>= fun () -> Lwt.task () |> fst) ]

type ws_conn = {
mutable frames_out_fn : (Websocket.Frame.t option -> unit) option;
Expand Down
2 changes: 1 addition & 1 deletion lib_httpq/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ let default_handler : handler = function
in
respond ~status ""

let start_server ?(port = 8080) ?error_handler (handler : handler) k : unit =
let start_server ?(port = 8080) ?error_handler (handler : handler) k : unit Lwt.t =
Bare_server.start_server port (k ())
@@ fun (req : Bare_server.Request.t) (body : Bare_server.Body.t) :
Bare_server.Response.t Lwt.t ->
Expand Down
3 changes: 3 additions & 0 deletions waq.opam
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ depends: [
"cohttp-lwt-unix"
"cppo"
"cstruct"
"eio"
"eio_main"
"dune" {>= "3.7"}
"fpath"
"jingoo"
"lambdasoup"
"lwt"
"lwt_eio"
"lwt_ppx"
"lwt_ssl"
"mirage-crypto-rng" {<= "0.10.7"}
Expand Down

0 comments on commit b3e58b9

Please sign in to comment.