mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
feat lwt_task: adaptative limit on number of tasks in one go
This commit is contained in:
parent
57bc8e434c
commit
906cc152f2
1 changed files with 5 additions and 6 deletions
|
|
@ -14,12 +14,11 @@ let on_uncaught_exn : (exn -> Printexc.raw_backtrace -> unit) ref =
|
|||
(Printexc.raw_backtrace_to_string bt))
|
||||
|
||||
let run_all_tasks () : unit =
|
||||
(* use local queue to prevent the hook from running forever in case
|
||||
tasks keep scheduling new tasks. *)
|
||||
let local = Queue.create () in
|
||||
Queue.transfer tasks local;
|
||||
while not (Queue.is_empty local) do
|
||||
let t = Queue.pop local in
|
||||
let n_processed = ref 0 in
|
||||
let max_number_of_steps = min 10_000 (2 * Queue.length tasks) in
|
||||
while (not (Queue.is_empty tasks)) && !n_processed < max_number_of_steps do
|
||||
let t = Queue.pop tasks in
|
||||
incr n_processed;
|
||||
try t ()
|
||||
with exn ->
|
||||
let bt = Printexc.get_raw_backtrace () in
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue