forked from go-rod/rod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
84 lines (71 loc) · 1.88 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package rod
import (
"context"
"time"
)
// Context creates a clone with a context that inherits the previous one
func (b *Browser) Context(ctx context.Context, cancel func()) *Browser {
newObj := *b
newObj.ctx = ctx
newObj.ctxCancel = cancel
return &newObj
}
// GetContext returns the current context
func (b *Browser) GetContext() context.Context {
return b.ctx
}
// Timeout for chained sub-operations
func (b *Browser) Timeout(d time.Duration) *Browser {
ctx, cancel := context.WithTimeout(b.ctx, d)
b.timeoutCancel = cancel
return b.Context(ctx, cancel)
}
// CancelTimeout context
func (b *Browser) CancelTimeout() *Browser {
b.timeoutCancel()
return b
}
// Context creates a clone with a context that inherits the previous one
func (p *Page) Context(ctx context.Context, cancel func()) *Page {
newObj := *p
newObj.ctx = ctx
newObj.ctxCancel = cancel
return &newObj
}
// GetContext returns the current context
func (p *Page) GetContext() context.Context {
return p.ctx
}
// Timeout for chained sub-operations
func (p *Page) Timeout(d time.Duration) *Page {
ctx, cancel := context.WithTimeout(p.ctx, d)
p.timeoutCancel = cancel
return p.Context(ctx, cancel)
}
// CancelTimeout context
func (p *Page) CancelTimeout() *Page {
p.timeoutCancel()
return p
}
// Context creates a clone with a context that inherits the previous one
func (el *Element) Context(ctx context.Context, cancel func()) *Element {
newObj := *el
newObj.ctx = ctx
newObj.ctxCancel = cancel
return &newObj
}
// GetContext returns the current context
func (el *Element) GetContext() context.Context {
return el.ctx
}
// Timeout for chained sub-operations
func (el *Element) Timeout(d time.Duration) *Element {
ctx, cancel := context.WithTimeout(el.ctx, d)
el.timeoutCancel = cancel
return el.Context(ctx, cancel)
}
// CancelTimeout context
func (el *Element) CancelTimeout() *Element {
el.timeoutCancel()
return el
}