diff --git a/dream-httpaf.opam b/dream-httpaf.opam
index 292bd829..1387d422 100644
--- a/dream-httpaf.opam
+++ b/dream-httpaf.opam
@@ -17,9 +17,7 @@ depends: [
"dune" {>= "2.7.0"} # --instrument-with.
"lwt"
"lwt_ppx" {>= "1.2.2"}
- "lwt_ssl"
"ocaml" {>= "4.08.0"}
- "ssl" {>= "0.5.8"} # Ssl.get_negotiated_alpn_protocol.
# Currently vendored.
# "gluten"
diff --git a/dream-pure.opam b/dream-pure.opam
index 6f6b7f26..b3a44e28 100644
--- a/dream-pure.opam
+++ b/dream-pure.opam
@@ -22,6 +22,7 @@ depends: [
"ocaml" {>= "4.08.0"}
"ptime" {>= "0.8.1"} # Ptime.weekday.
"uri" {>= "4.2.0"}
+ "eio" {>= "0.2"}
# Testing, development.
"alcotest" {with-test}
diff --git a/dream.opam b/dream.opam
index 07e14a0b..56110801 100644
--- a/dream.opam
+++ b/dream.opam
@@ -62,7 +62,6 @@ depends: [
"graphql-lwt"
"lwt"
"lwt_ppx" {>= "1.2.2"}
- "lwt_ssl"
"logs" {>= "0.5.0"}
"magic-mime"
"mirage-clock" {>= "3.0.0"} # now_d_ps : unit -> int * int64.
@@ -73,9 +72,10 @@ depends: [
"multipart_form-lwt"
"ocaml" {>= "4.08.0"}
"ptime" {>= "0.8.1"} # Ptime.v.
- "ssl" {>= "0.5.8"} # Ssl.get_negotiated_alpn_protocol.
"uri" {>= "4.2.0"}
"yojson" # ...
+ "eio_main" {>= "0.2"}
+ "lwt_eio" {>= "0.1"}
# Testing, development.
"alcotest" {with-test}
diff --git a/example/1-hello/README.md b/example/1-hello/README.md
index 9de605ca..22909023 100644
--- a/example/1-hello/README.md
+++ b/example/1-hello/README.md
@@ -6,8 +6,10 @@ This project is so simple that it doesn't even log requests!
```ocaml
let () =
- Dream.run (fun _ ->
- Dream.html "Good morning, world!")
+ Eio_main.run (fun env ->
+ Dream.run env (fun _ ->
+ Dream.html "Good morning, world!")
+ )
```
@@ -39,6 +41,11 @@ name of the `.ml` file, but with `.ml` changed to `.exe`.
+A Dream server runs in an [Eio](https://github.com/ocaml-multicore/eio) event loop,
+which is created by `Eio_main.run`.
+
+
+
**Next steps:**
- The next example, [**`2-middleware`**](../2-middleware#files), adds a logger
diff --git a/example/1-hello/hello.ml b/example/1-hello/hello.ml
index 5411c9ee..83de636c 100644
--- a/example/1-hello/hello.ml
+++ b/example/1-hello/hello.ml
@@ -1,3 +1,5 @@
let () =
- Dream.run (fun _ ->
- Dream.html "Good morning, world!")
+ Eio_main.run (fun env ->
+ Dream.run env (fun _ ->
+ Dream.html "Good morning, world!")
+ )
diff --git a/example/2-middleware/README.md b/example/2-middleware/README.md
index 5ec6b67e..3949861e 100644
--- a/example/2-middleware/README.md
+++ b/example/2-middleware/README.md
@@ -9,9 +9,10 @@ middlewares, the [*logger*](https://aantron.github.io/dream/#val-logger):
```ocaml
let () =
- Dream.run
- (Dream.logger (fun _ ->
- Dream.html "Good morning, world!"))
+ Eio_main.run (fun env ->
+ Dream.run env
+ (Dream.logger (fun _ ->
+ Dream.html "Good morning, world!")))
```
@@ -25,7 +26,8 @@ in this example looks like this:
```ocaml
let () =
- Dream.run
+ Eio_main.run @@ fun env ->
+ Dream.run env
@@ Dream.logger
@@ fun _ -> Dream.html "Good morning, world!"
```
diff --git a/example/2-middleware/middleware.ml b/example/2-middleware/middleware.ml
index a35eb21d..c04d64f5 100644
--- a/example/2-middleware/middleware.ml
+++ b/example/2-middleware/middleware.ml
@@ -1,4 +1,5 @@
let () =
- Dream.run
+ Eio_main.run @@ fun env ->
+ Dream.run env
@@ Dream.logger
@@ fun _ -> Dream.html "Good morning, world!"
diff --git a/example/3-router/router.ml b/example/3-router/router.ml
index fb1a9dab..fc0ede3a 100644
--- a/example/3-router/router.ml
+++ b/example/3-router/router.ml
@@ -1,5 +1,6 @@
let () =
- Dream.run
+ Eio_main.run @@ fun env ->
+ Dream.run env
@@ Dream.logger
@@ Dream.router [
diff --git a/example/4-counter/counter.ml b/example/4-counter/counter.ml
index 2a1d10ac..6581b441 100644
--- a/example/4-counter/counter.ml
+++ b/example/4-counter/counter.ml
@@ -5,7 +5,8 @@ let count_requests inner_handler request =
inner_handler request
let () =
- Dream.run
+ Eio_main.run @@ fun env ->
+ Dream.run env
@@ Dream.logger
@@ count_requests
@@ Dream.router [
diff --git a/example/5-promise/README.md b/example/5-promise/README.md
index a8d932e3..63e7575e 100644
--- a/example/5-promise/README.md
+++ b/example/5-promise/README.md
@@ -1,29 +1,30 @@
# `5-promise`
+(note this example is now badly named, as it doesn't use any promises)
+
[**`4-counter`**](../4-counter#files) was limited to counting requests *before*
-passing them on to the rest of the app. With the promise library
-[Lwt](https://github.com/ocsigen/lwt), we can await responses, and do something
-*after*. In this example, we separately count requests that were handled
-successfully, and those that caused an exception:
+passing them on to the rest of the app. We can also await responses, and do
+something *after*. In this example, we separately count requests that were
+handled successfully, and those that caused an exception:
```ocaml
let successful = ref 0
let failed = ref 0
let count_requests inner_handler request =
- try%lwt
- let%lwt response = inner_handler request in
+ try
+ let response = inner_handler request in
successful := !successful + 1;
- Lwt.return response
-
+ response
with exn ->
failed := !failed + 1;
raise exn
let () =
- Dream.run
+ Eio_main.run @@ fun env ->
+ Dream.run env
@@ Dream.logger
@@ count_requests
@@ Dream.router [
@@ -48,49 +49,13 @@ Try it in the [playground](http://dream.as/5-promise).
-As you can see, the
-[core constructs](https://ocsigen.org/lwt/latest/api/Ppx_lwt) of Lwt are:
-
-- `let%lwt` to await the result of a promise.
-- `try%lwt` to catch both exceptions and rejections. Lwt promises can only be
- rejected with exceptions, of OCaml type `exn`.
-- `Lwt.return` to resolve a promise.
-
-Besides these, Lwt has a lot of [convenience
-functions](https://ocsigen.org/lwt/latest/api/Lwt), and an [asychronous
-I/O library](https://ocsigen.org/lwt/latest/api/Lwt_unix).
+As you can see, we use `try` to catch both exceptions and rejections.
-To use `let%lwt`, we need to modify our
-[`dune`](https://github.com/aantron/dream/blob/master/example/5-promise/dune)
-file a bit to include `lwt_ppx`:
-
-
(executable
- (name promise)
- (libraries dream)
- (preprocess (pps lwt_ppx)))
-
-
-There are other ways to write *await* and *catch* in Lwt that don't require
-`lwt_ppx`, but `lwt_ppx` is presently the best for preserving nice stack traces.
-For example, `let%lwt` is equivalent to...
-
-- [`Lwt.bind`](https://github.com/ocsigen/lwt/blob/c5f895e35a38df2d06f19fd23bf553129b9e95b3/src/core/lwt.mli#L475),
- which is almost never used directly.
-- [`>>=`](https://github.com/ocsigen/lwt/blob/c5f895e35a38df2d06f19fd23bf553129b9e95b3/src/core/lwt.mli#L1395)
- from module `Lwt.Infix`.
-- [`let*`](https://github.com/ocsigen/lwt/blob/c5f895e35a38df2d06f19fd23bf553129b9e95b3/src/core/lwt.mli#L1511)
- from module `Lwt.Syntax`, which is showcased in Lwt's
- [README](https://github.com/ocsigen/lwt#readme).
-
-We will stick to `let%lwt` in the examples and keep things tidy.
-
-(executable
(name template)
- (libraries dream)
- (preprocess (pps lwt_ppx)))
+ (libraries dream))
(rule
(targets template.ml)
diff --git a/example/7-template/template.eml.ml b/example/7-template/template.eml.ml
index f6cd751e..7e185cc0 100644
--- a/example/7-template/template.eml.ml
+++ b/example/7-template/template.eml.ml
@@ -6,7 +6,8 @@ let render param =