Adding safeguards around Shutdown and AddTarget

This commit is contained in:
Kenneth Shaw 2017-03-13 09:09:57 +07:00
parent 8c9e75e5ab
commit ddaa7bc4e7
2 changed files with 12 additions and 1 deletions

4
.gitignore vendored
View File

@ -9,4 +9,8 @@ massif.out
# binaries # binaries
/chromedp-gen /chromedp-gen
/chromedp-proxy
/chromedp-cli
/cmd/chromedp-gen/chromedp-gen /cmd/chromedp-gen/chromedp-gen
/cmd/chromedp-gen/chromedp-proxy
/cmd/chromedp-gen/chromedp-cli

View File

@ -75,6 +75,9 @@ func New(ctxt context.Context, opts ...Option) (*CDP, error) {
go func() { go func() {
for t := range c.watch { for t := range c.watch {
if t == nil {
return
}
go c.AddTarget(ctxt, t) go c.AddTarget(ctxt, t)
} }
}() }()
@ -153,7 +156,11 @@ func (c *CDP) Shutdown(ctxt context.Context, opts ...client.Option) error {
c.RLock() c.RLock()
defer c.RUnlock() defer c.RUnlock()
return c.r.Shutdown(ctxt, opts...) if c.r != nil {
return c.r.Shutdown(ctxt, opts...)
}
return nil
} }
// ListTargets returns the target IDs of the managed targets. // ListTargets returns the target IDs of the managed targets.