Fix repeat timing: don't double-drive IO suspensions

The value_to_js resume handler was calling _driveAsync on re-suspension,
but the JS driveAsync caller also processes the returned suspension.
This caused the second wait in each iteration to fire immediately (0ms)
instead of respecting the delay.

Fix: resume handler just returns the suspension object, lets the JS
driveAsync handle scheduling via setTimeout.

Verified: repeat 3 times add/wait 300ms/remove/wait 300ms produces
6 transitions at correct 300ms intervals (1504ms total).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 21:47:48 +00:00
parent 9982cd5926
commit 0bed9e3664
3 changed files with 8 additions and 16 deletions

View File

@@ -121,11 +121,8 @@ let rec value_to_js (v : value) : Js.Unsafe.any =
try value_to_js (Sx_vm.resume_vm v result)
with
| Sx_vm.VmSuspended (req2, vm2) ->
let s = make_suspension req2 vm2 in
let drive = Js.Unsafe.get Js.Unsafe.global (Js.string "_driveAsync") in
if not (Js.Unsafe.equals drive Js.undefined) then
ignore (Js.Unsafe.fun_call drive [| Js.Unsafe.inject s |]);
Js.Unsafe.inject s
(* Return suspension object — the JS driveAsync caller handles scheduling *)
Js.Unsafe.inject (make_suspension req2 vm2)
| Eval_error msg ->
ignore (Js.Unsafe.meth_call
(Js.Unsafe.get Js.Unsafe.global (Js.string "console"))

File diff suppressed because one or more lines are too long

View File

@@ -1792,7 +1792,7 @@
blake2_js_for_wasm_create: blake2_js_for_wasm_create};
}
(globalThis))
({"link":[["runtime-0db9b496",0],["prelude-d7e4b000",0],["stdlib-23ce0836",[]],["re-9a0de245",[2]],["sx-42ed14c8",[2,3]],["jsoo_runtime-f96b44a8",[2]],["js_of_ocaml-651f6707",[2,5]],["dune__exe__Sx_browser-df4c0015",[2,4,6]],["std_exit-10fb8830",[2]],["start-f808dbe1",0]],"generated":(b=>{var
({"link":[["runtime-0db9b496",0],["prelude-d7e4b000",0],["stdlib-23ce0836",[]],["re-9a0de245",[2]],["sx-42ed14c8",[2,3]],["jsoo_runtime-f96b44a8",[2]],["js_of_ocaml-651f6707",[2,5]],["dune__exe__Sx_browser-acaac3c1",[2,4,6]],["std_exit-10fb8830",[2]],["start-f808dbe1",0]],"generated":(b=>{var
c=b,a=b?.module?.export||b;return{"env":{"caml_ba_kind_of_typed_array":()=>{throw new
Error("caml_ba_kind_of_typed_array not implemented")},"caml_exn_with_js_backtrace":()=>{throw new
Error("caml_exn_with_js_backtrace not implemented")},"caml_int64_create_lo_mi_hi":()=>{throw new