all: remove unnecessary loop labels
All of them are used for a single return, so use the return instead.
This commit is contained in:
parent
a9647b3e5b
commit
7ed029cf24
14
chromedp.go
14
chromedp.go
|
@ -85,7 +85,6 @@ func New(ctxt context.Context, opts ...Option) (*CDP, error) {
|
||||||
// TODO: fix this
|
// TODO: fix this
|
||||||
timeout := time.After(defaultNewTargetTimeout)
|
timeout := time.After(defaultNewTargetTimeout)
|
||||||
|
|
||||||
loop:
|
|
||||||
// wait until at least one target active
|
// wait until at least one target active
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -104,11 +103,9 @@ loop:
|
||||||
return nil, ctxt.Err()
|
return nil, ctxt.Err()
|
||||||
|
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New("timeout waiting for initial target")
|
return nil, errors.New("timeout waiting for initial target")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTarget adds a target using the supplied context.
|
// AddTarget adds a target using the supplied context.
|
||||||
|
@ -243,7 +240,6 @@ func (c *CDP) newTarget(ctxt context.Context, opts ...client.Option) (string, er
|
||||||
|
|
||||||
timeout := time.After(DefaultNewTargetTimeout)
|
timeout := time.After(DefaultNewTargetTimeout)
|
||||||
|
|
||||||
loop:
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
default:
|
default:
|
||||||
|
@ -262,11 +258,9 @@ loop:
|
||||||
return "", ctxt.Err()
|
return "", ctxt.Err()
|
||||||
|
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", errors.New("timeout waiting for new target to be available")
|
return "", errors.New("timeout waiting for new target to be available")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTarget is an action that sets the active Chrome handler to the specified
|
// SetTarget is an action that sets the active Chrome handler to the specified
|
||||||
|
|
19
handler.go
19
handler.go
|
@ -397,7 +397,6 @@ func (h *TargetHandler) next() int64 {
|
||||||
func (h *TargetHandler) GetRoot(ctxt context.Context) (*cdp.Node, error) {
|
func (h *TargetHandler) GetRoot(ctxt context.Context) (*cdp.Node, error) {
|
||||||
var root *cdp.Node
|
var root *cdp.Node
|
||||||
|
|
||||||
loop:
|
|
||||||
for {
|
for {
|
||||||
var cur *cdp.Frame
|
var cur *cdp.Frame
|
||||||
select {
|
select {
|
||||||
|
@ -412,7 +411,7 @@ loop:
|
||||||
h.RUnlock()
|
h.RUnlock()
|
||||||
|
|
||||||
if cur != nil && root != nil {
|
if cur != nil && root != nil {
|
||||||
break loop
|
return root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(DefaultCheckDuration)
|
time.Sleep(DefaultCheckDuration)
|
||||||
|
@ -421,8 +420,6 @@ loop:
|
||||||
return nil, ctxt.Err()
|
return nil, ctxt.Err()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return root, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetActive sets the currently active frame after a successful navigation.
|
// SetActive sets the currently active frame after a successful navigation.
|
||||||
|
@ -448,7 +445,6 @@ func (h *TargetHandler) WaitFrame(ctxt context.Context, id cdp.FrameID) (*cdp.Fr
|
||||||
// TODO: fix this
|
// TODO: fix this
|
||||||
timeout := time.After(10 * time.Second)
|
timeout := time.After(10 * time.Second)
|
||||||
|
|
||||||
loop:
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
default:
|
default:
|
||||||
|
@ -473,11 +469,9 @@ loop:
|
||||||
return nil, ctxt.Err()
|
return nil, ctxt.Err()
|
||||||
|
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("timeout waiting for frame `%s`", id)
|
return nil, fmt.Errorf("timeout waiting for frame `%s`", id)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitNode waits for a node to be loaded using the provided context.
|
// WaitNode waits for a node to be loaded using the provided context.
|
||||||
|
@ -485,7 +479,6 @@ func (h *TargetHandler) WaitNode(ctxt context.Context, f *cdp.Frame, id cdp.Node
|
||||||
// TODO: fix this
|
// TODO: fix this
|
||||||
timeout := time.After(10 * time.Second)
|
timeout := time.After(10 * time.Second)
|
||||||
|
|
||||||
loop:
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
default:
|
default:
|
||||||
|
@ -506,11 +499,9 @@ loop:
|
||||||
return nil, ctxt.Err()
|
return nil, ctxt.Err()
|
||||||
|
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("timeout waiting for node `%d`", id)
|
return nil, fmt.Errorf("timeout waiting for node `%d`", id)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pageEvent handles incoming page events.
|
// pageEvent handles incoming page events.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user