From: Stephane Glondu Date: Sat, 9 May 2026 08:57:58 +0200 Subject: Fix build with lwt 6 --- src/USB.ml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/USB.ml b/src/USB.ml index cb4bf79..041234a 100644 --- a/src/USB.ml +++ b/src/USB.ml @@ -231,11 +231,11 @@ let init = lazy( (* Initializes libusb. *) ml_usb_init (); (* Integrate libusb timoeuts into lwt. *) - ignore (Lwt_sequence.add_r enter_iter Lwt_main.enter_iter_hooks); - ignore (Lwt_sequence.add_r leave_iter Lwt_main.leave_iter_hooks); + ignore (Lwt_main.Enter_iter_hooks.add_last enter_iter); + ignore (Lwt_main.Leave_iter_hooks.add_last leave_iter); (* Cleanup libusb on exit. *) let exit = lazy(ml_usb_exit ()) in - ignore (Lwt_sequence.add_r (fun _ -> Lazy.force exit |> Lwt.return) Lwt_main.exit_hooks) + ignore (Lwt_main.Exit_hooks.add_last (fun _ -> Lazy.force exit |> Lwt.return)) ) let set_debug level = @@ -265,12 +265,22 @@ let make_handle device_handle = { let check_handle handle = if handle.state = State_closed then failwith "device handle closed" +let execute_job ?async_method ~job ~result ~free () = + Lwt.finalize + (fun () -> + Lwt.bind + (run_job ?async_method job) + (fun _ -> Lwt.return (result job))) + (fun () -> + free job; + Lwt.return_unit) + let detach handle job result free = Lwt_mutex.with_lock handle.mutex begin fun () -> check_handle handle; handle.state <- State_detach; Lwt.finalize - (fun () -> execute_job ?async_method:None ~job:(job ()) ~result ~free) + (fun () -> execute_job ?async_method:None ~job:(job ()) ~result ~free ()) (fun () -> if handle.state = State_detach then handle.state <- State_ok;