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:
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user