Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 0f56fbc

Browse files
committed
Use a timer instead of sleeping
Sleeping will last for a short amount of time as setting execution contexts happens pretty fast. I don't think sleeping here will be a problem, but I have a solution for not sleeping here as well. But I'm not sure whether it's necessary, as it can complicate this code.
1 parent 918d5e0 commit 0f56fbc

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

common/frame.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -476,29 +476,18 @@ func (f *Frame) waitForExecutionContext(world string) {
476476
f.log.Debugf("Frame:waitForExecutionContext", "fid:%s furl:%q world:%s",
477477
f.ID(), f.URL(), world)
478478

479-
wait := func(done chan struct{}) {
480-
var ok bool
479+
t := time.NewTimer(50 * time.Millisecond)
480+
defer t.Stop()
481+
for {
481482
select {
483+
case <-t.C:
484+
if f.hasContext(world) {
485+
return
486+
}
482487
case <-f.ctx.Done():
483-
ok = true
484-
default:
485-
ok = f.hasContext(world)
486-
}
487-
if !ok {
488-
// TODO: change sleeping with something else
489-
time.Sleep(time.Millisecond * 50)
490488
return
491489
}
492-
done <- struct{}{}
493490
}
494-
495-
done := make(chan struct{})
496-
go func() {
497-
for {
498-
wait(done)
499-
}
500-
}()
501-
<-done
502491
}
503492

504493
func (f *Frame) waitForFunction(apiCtx context.Context, world string, predicateFn goja.Value, polling PollingType, interval int64, timeout time.Duration, args ...goja.Value) (interface{}, error) {

0 commit comments

Comments
 (0)