@@ -153,7 +153,7 @@ export fn lightpanda_cdp_browser_context(cdp_ptr: *anyopaque) *anyopaque {
153153 return & cdp .browser_context .? ;
154154}
155155
156- // returns -1 if no session/page, or if no events reamin, otherwise returns
156+ // returns -1 if no session/page, or if no events reamin, otherwise returns
157157// milliseconds until next scheduled task
158158export fn lightpanda_cdp_page_wait (cdp_ptr : * anyopaque , ms : i32 ) c_int {
159159 const cdp : * CDP = @ptrCast (@alignCast (cdp_ptr ));
@@ -165,14 +165,20 @@ export fn lightpanda_cdp_page_wait(cdp_ptr: *anyopaque, ms: i32) c_int {
165165}
166166
167167fn cdp_peek_next_delay_ms (scheduler : * Scheduler ) ? i32 {
168- if (scheduler .high_priority .count () == 0 ) {
169- return null ;
170- }
168+ var queue = queue : {
169+ if (scheduler .high_priority .count () == 0 ) {
170+ if (scheduler .low_priority .count () == 0 ) return null ;
171+ break :queue scheduler .low_priority ;
172+ } else {
173+ break :queue scheduler .high_priority ;
174+ }
175+ };
171176
172177 const now = std .time .milliTimestamp ();
173- const next_task = scheduler . high_priority . peek () .? ;
174- const time_to_next = next_task . ms - now ;
178+ // we know this must exist because the count was not 0.
179+ const next_task = queue . peek () .? ;
175180
181+ const time_to_next = next_task .ms - now ;
176182 return if (time_to_next > 0 ) @intCast (time_to_next ) else 0 ;
177183}
178184
0 commit comments