-
Notifications
You must be signed in to change notification settings - Fork 8
/
module.go
50 lines (40 loc) · 896 Bytes
/
module.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
package sse
import (
"go.k6.io/k6/js/common"
"go.k6.io/k6/js/modules"
)
type (
// RootModule is the global module instance that will create module
// instances for each VU.
RootModule struct{}
)
var (
_ modules.Module = &RootModule{}
_ modules.Instance = &sse{}
)
// New returns a pointer to a new RootModule instance.
func New() *RootModule {
return &RootModule{}
}
// NewModuleInstance implements the modules.Module interface to return
// a new instance for each VU.
func (*RootModule) NewModuleInstance(m modules.VU) modules.Instance {
rt := m.Runtime()
mi := &sse{
vu: m,
}
obj := rt.NewObject()
if err := obj.Set("open", mi.Open); err != nil {
common.Throw(rt, err)
}
mi.obj = obj
metrics, err := registerMetrics(m)
if err != nil {
common.Throw(rt, err)
}
mi.metrics = &metrics
return mi
}
func init() {
modules.Register("k6/x/sse", new(RootModule))
}