Skip to content

Commit

Permalink
Wrap in Lwt.async
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Aug 2, 2023
1 parent 47e2dc0 commit 74de672
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/react/src/react.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ let createContext (initial_value : 'a) : 'a context =

module Suspense = struct
let make ~fallback ~children = Suspense { fallback; children }
end
end [@react.component]

(* let memo f : 'props * 'props -> bool = f
let memoCustomCompareProps f _compare : 'props * 'props -> bool = f *)
Expand Down
27 changes: 14 additions & 13 deletions packages/reactDom/src/reactDOM.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,20 @@ let render_to_stream ~context_state element =
let current_boundary_id = context_state.boundary_id in
let current_suspense_id = context_state.suspense_id in
(* Wait for promise to resolve *)
Lwt.map
(fun _ ->
context_state.push
(render_resolved_element ~id:current_suspense_id children);
context_state.push inline_complete_boundary_script;
context_state.push
(render_inline_rc_replacement
[ (current_boundary_id, current_suspense_id) ]);
context_state.waiting <- context_state.waiting - 1;
context_state.suspense_id <- context_state.suspense_id + 1;
if context_state.waiting = 0 then context_state.close () else ())
promise
|> Lwt.ignore_result;
Lwt.async (fun () ->
Lwt.map
(fun _ ->
context_state.push
(render_resolved_element ~id:current_suspense_id children);
context_state.push inline_complete_boundary_script;
context_state.push
(render_inline_rc_replacement
[ (current_boundary_id, current_suspense_id) ]);
context_state.waiting <- context_state.waiting - 1;
context_state.suspense_id <- context_state.suspense_id + 1;
if context_state.waiting = 0 then context_state.close ()
else ())
promise);
context_state.boundary_id <- context_state.boundary_id + 1;
(* Render the fallback state *)
Printf.sprintf "<!--$?--><template id='B:%i'></template>%s<!--/$-->"
Expand Down
2 changes: 1 addition & 1 deletion server-reason-react.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ depends: [
"reason" {>= "3.8.1"}
"pcre" {>= "7.4.0"}
"promise" {>= "1.1.2"}
"alcotest" {with-test}
"lwt" {>= "5.6.0"}
"alcotest" {with-test}
"fmt" {with-test}
"ocamlformat" {= "0.21.0" & with-test}
"ocaml-lsp-server" {with-test}
Expand Down

0 comments on commit 74de672

Please sign in to comment.