From ec1f601e4fb509f47f0fedbcf5a899fb3e696e5c Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 25 Nov 2024 17:31:45 +0200 Subject: [PATCH] js/modules: update docs around NewModuleInstance 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` --- js/modules/modules.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/modules/modules.go b/js/modules/modules.go index a01101257b0..ecf24c3b95e 100644 --- a/js/modules/modules.go +++ b/js/modules/modules.go @@ -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" @@ -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 }