You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following snippet (it's not a strictly minimal example; I hope that's fine):
openDreamopenEffectopenEffect.DeepopenPpx_yojson_conv_lib.Yojson_conv.Primitivestypeuser_object = {
email : string;token: string;username: string;bio: string;image: stringoption;
} [@@deriving yojson]
typelogin_user_object = {
email : string;password: string;
} [@@deriving yojson]
typelogin_object = {
user: login_user_object;
} [@@deriving yojson]
type_ Effect.t += User_login : login_object -> user_objectEffect.tletuser_loginx=User_login x |> perform
letwith_handlersfx=
try_with f x
{ effc =fun (typea) (eff: a t) ->
match eff with|User_login_ -> Some (fun (k: (a, _) continuation) ->
continue k { email ="test"; token ="test"; username ="test"; bio ="test"; image =None })
|_ -> None }
let main()=
run ~error_handler: debug_error_handler
@@ logger
@@ router [
get "/" (fun_ -> html "Hello, world!");
post "/api/users/login"@@
(funrequest ->
let%lwt body =Dream.body request in
body
|>Yojson.Safe.from_string
|> login_object_of_yojson
|> user_login
|> yojson_of_user_object
|>Yojson.Safe.to_string
|> json);
]
let()= with_handlers main ()
Making a POST /api/users/login request with a valid payload fails because the effect appears to be unhandled. As well as the following variation:
(* ... snip ... *)let()=
run ~error_handler: debug_error_handler
@@ logger
@@ router [
get "/" (fun_ -> html "Hello, world!");
post "/api/users/login"@@
with_handlers (funrequest ->
let%lwt body =Dream.body request in
body
|>Yojson.Safe.from_string
|> login_object_of_yojson
|> user_login
|> yojson_of_user_object
|>Yojson.Safe.to_string
|> json);
]
Lwt seems at fault here, as moving with_handlers inside let%lwt or not parsing the request body at all works as expected with the second variation. Are there any tips on how to use Dream with some top-level effect handlers? Either by installing them in a way that works with Lwt or duplicating them more ergonomically than just carefully spotting all use of async API from Dream and manually inserting effect handler inside the promise handlers.
The text was updated successfully, but these errors were encountered:
Consider the following snippet (it's not a strictly minimal example; I hope that's fine):
Making a
POST /api/users/login
request with a valid payload fails because the effect appears to be unhandled. As well as the following variation:Lwt seems at fault here, as moving
with_handlers
insidelet%lwt
or not parsing the request body at all works as expected with the second variation. Are there any tips on how to use Dream with some top-level effect handlers? Either by installing them in a way that works with Lwt or duplicating them more ergonomically than just carefully spotting all use of async API from Dream and manually inserting effect handler inside the promise handlers.The text was updated successfully, but these errors were encountered: