@@ -321,6 +321,7 @@ pub const Page = struct {
321321 // store http_client.active BEFORE this call and then use
322322 // it AFTER.
323323 const ms_to_next_task = try scheduler .runHighPriority ();
324+ _ = try scheduler .runLowPriority ();
324325
325326 if (try_catch .hasCaught ()) {
326327 const msg = (try try_catch .err (self .arena )) orelse "unknown" ;
@@ -329,7 +330,17 @@ pub const Page = struct {
329330 }
330331
331332 if (http_client .active == 0 and exit_when_done ) {
332- const ms = ms_to_next_task orelse {
333+ const ms = ms_to_next_task orelse blk : {
334+ // TODO: when jsRunner is fully replaced with the
335+ // htmlRunner, we can remove the first part of this
336+ // condition. jsRunner calls `page.wait` far too
337+ // often to enforce this.
338+ if (wait_ms > 100 and wait_ms - ms_remaining < 100 ) {
339+ // Look, we want to exit ASAP, but we don't want
340+ // to exit so fast that we've run none of the
341+ // background jobs.
342+ break :blk 50 ;
343+ }
333344 // no http transfers, no cdp extra socket, no
334345 // scheduled tasks, we're done.
335346 return .done ;
@@ -341,7 +352,6 @@ pub const Page = struct {
341352 return .done ;
342353 }
343354
344- _ = try scheduler .runLowPriority ();
345355 // we have a task to run in the not-so-distant future.
346356 // You might think we can just sleep until that task is
347357 // ready, but we should continue to run lowPriority tasks
@@ -353,7 +363,6 @@ pub const Page = struct {
353363 // We're here because we either have active HTTP
354364 // connections, of exit_when_done == false (aka, there's
355365 // an extra_socket registered with the http client).
356- _ = try scheduler .runLowPriority ();
357366 const ms_to_wait = @min (ms_remaining , ms_to_next_task orelse 100 );
358367 if (try http_client .tick (ms_to_wait ) == .extra_socket ) {
359368 // data on a socket we aren't handling, return to caller
0 commit comments