all: remove unnecessary loop labels

All of them are used for a single return, so use the return instead.
This commit is contained in:
Daniel Martí 2017-11-25 20:15:28 +00:00 committed by Kenneth Shaw
parent a9647b3e5b
commit 7ed029cf24
2 changed files with 5 additions and 20 deletions

View File

@ -85,7 +85,6 @@ func New(ctxt context.Context, opts ...Option) (*CDP, error) {
// TODO: fix this
timeout := time.After(defaultNewTargetTimeout)
loop:
// wait until at least one target active
for {
select {
@ -104,12 +103,10 @@ loop:
return nil, ctxt.Err()
case <-timeout:
break loop
}
}
return nil, errors.New("timeout waiting for initial target")
}
}
}
// AddTarget adds a target using the supplied context.
func (c *CDP) AddTarget(ctxt context.Context, t client.Target) {
@ -243,7 +240,6 @@ func (c *CDP) newTarget(ctxt context.Context, opts ...client.Option) (string, er
timeout := time.After(DefaultNewTargetTimeout)
loop:
for {
select {
default:
@ -262,12 +258,10 @@ loop:
return "", ctxt.Err()
case <-timeout:
break loop
}
}
return "", errors.New("timeout waiting for new target to be available")
}
}
}
// SetTarget is an action that sets the active Chrome handler to the specified
// index i.

View File

@ -397,7 +397,6 @@ func (h *TargetHandler) next() int64 {
func (h *TargetHandler) GetRoot(ctxt context.Context) (*cdp.Node, error) {
var root *cdp.Node
loop:
for {
var cur *cdp.Frame
select {
@ -412,7 +411,7 @@ loop:
h.RUnlock()
if cur != nil && root != nil {
break loop
return root, nil
}
time.Sleep(DefaultCheckDuration)
@ -421,8 +420,6 @@ loop:
return nil, ctxt.Err()
}
}
return root, nil
}
// 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
timeout := time.After(10 * time.Second)
loop:
for {
select {
default:
@ -473,19 +469,16 @@ loop:
return nil, ctxt.Err()
case <-timeout:
break loop
}
}
return nil, fmt.Errorf("timeout waiting for frame `%s`", id)
}
}
}
// WaitNode waits for a node to be loaded using the provided context.
func (h *TargetHandler) WaitNode(ctxt context.Context, f *cdp.Frame, id cdp.NodeID) (*cdp.Node, error) {
// TODO: fix this
timeout := time.After(10 * time.Second)
loop:
for {
select {
default:
@ -506,12 +499,10 @@ loop:
return nil, ctxt.Err()
case <-timeout:
break loop
}
}
return nil, fmt.Errorf("timeout waiting for node `%d`", id)
}
}
}
// pageEvent handles incoming page events.
func (h *TargetHandler) pageEvent(ctxt context.Context, ev interface{}) {