Skip to content

Commit

Permalink
Merge pull request #1016 from tleedjarv/fix-990+1006
Browse files Browse the repository at this point in the history
Fix a recursion to allow tail call elimination
  • Loading branch information
gdt authored Apr 2, 2024
2 parents f55cf70 + 906ef81 commit 9c8cd36
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 9c8cd36

Please sign in to comment.