forked from playwright-community/playwright-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel_owner.go
57 lines (51 loc) · 1.35 KB
/
channel_owner.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
package playwright
import "sync"
type channelOwner struct {
sync.RWMutex
eventEmitter
objectType string
guid string
channel *channel
objects map[string]*channelOwner
connection *connection
initializer map[string]interface{}
parent *channelOwner
}
func (c *channelOwner) Dispose() {
// Clean up from parent and connection.
if c.parent != nil {
delete(c.parent.objects, c.guid)
}
delete(c.connection.objects, c.guid)
// Dispose all children.
for _, object := range c.objects {
object.Dispose()
}
c.objects = make(map[string]*channelOwner)
}
func (c *channelOwner) createChannelOwner(self interface{}, parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) {
c.objectType = objectType
c.guid = guid
c.parent = parent
c.objects = make(map[string]*channelOwner)
c.connection = parent.connection
c.channel = newChannel(c.connection, guid)
c.channel.object = self
c.initializer = initializer
c.connection.objects[guid] = c
c.parent.objects[guid] = c
c.initEventEmitter()
}
func newRootChannelOwner(connection *connection) *channelOwner {
c := &channelOwner{
objectType: "",
guid: "",
connection: connection,
objects: make(map[string]*channelOwner),
channel: newChannel(connection, ""),
}
c.channel.object = c
c.connection.objects[""] = c
c.initEventEmitter()
return c
}