Skip to content

Commit

Permalink
js/modules: update docs around NewModuleInstance
Browse files Browse the repository at this point in the history
The previous comment made it seem that for each invocation of `require`
or `import` it will be called for each VU. While it only gets called on
the first `require`/`import`.

While this is only gets called the first time it is required for each VU
that `imports`/`require`
  • Loading branch information
mstoykov committed Nov 25, 2024
1 parent 135f85b commit ec1f601
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions js/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/grafana/sobek"

"go.k6.io/k6/ext"
"go.k6.io/k6/js/common"
"go.k6.io/k6/lib"
Expand All @@ -27,8 +28,8 @@ func Register(name string, mod interface{}) {

// Module is the interface js modules should implement in order to get access to the VU
type Module interface {
// NewModuleInstance will get modules.VU that should provide the module with a way to interact with the VU
// This method will be called for *each* require/import and should return an unique instance for each call
// NewModuleInstance will get modules.VU that should provide the module with a way to interact with the VU.
// This method will be called for *each* VU that imports the module *once* per that VU.
NewModuleInstance(VU) Instance
}

Expand Down

0 comments on commit ec1f601

Please sign in to comment.