Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a recursion to allow tail call elimination #1016

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/transport.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,21 @@ let run dispenseTask =
let avail = ref limit in
let rec runTask thr =
Lwt.try_bind thr
(fun () -> nextTask (); Lwt.return ())
(fun _ -> nextTask (); assert false)
(fun () -> nextTask ())
(fun _ -> assert false)
(* It is a programming error for an exception to reach this far. *)
|> ignore
and nextTask () =
match dispenseTask () with
| None -> incr avail
| None -> Lwt.return (incr avail)
| Some thr -> runTask thr
in
let rec fillPool () =
match dispenseTask () with
| None -> ()
| Some thr -> decr avail; runTask thr; if !avail > 0 then fillPool ()
| Some thr ->
decr avail;
let _ : unit Lwt.t = runTask thr in
if !avail > 0 then fillPool ()
in
fillPool ()
in
Expand Down
Loading