| 68 | } |
| 69 | |
| 70 | func (ms *ModuleSystem) getModuleInstanceFromGoModule(wm *goModule) (wmi *goModuleInstance, err error) { |
| 71 | rt := ms.vu.Runtime() |
| 72 | mi := rt.GetModuleInstance(wm) |
| 73 | if mi == nil { |
| 74 | err = wm.Link() |
| 75 | if err != nil { |
| 76 | return nil, err |
| 77 | } |
| 78 | promise := rt.CyclicModuleRecordEvaluate(wm, ms.resolver.sobekModuleResolver) |
| 79 | switch promise.State() { |
| 80 | case sobek.PromiseStateRejected: |
| 81 | err = promise.Result().Export().(error) //nolint:forcetypeassert |
| 82 | case sobek.PromiseStateFulfilled: |
| 83 | default: |
| 84 | panic("TLA in go modules is not supported in k6 at the moment") |
| 85 | } |
| 86 | if err != nil { |
| 87 | return nil, err |
| 88 | } |
| 89 | mi = rt.GetModuleInstance(wm) |
| 90 | } |
| 91 | gmi, ok := mi.(*goModuleInstance) |
| 92 | if !ok { |
| 93 | panic(fmt.Sprintf("a goModule instance is of not goModuleInstance type (got %T). "+ |
| 94 | "This is a k6 bug please report it (https://github.com/grafana/k6/issues)", mi)) |
| 95 | } |
| 96 | return gmi, nil |
| 97 | } |
| 98 | |
| 99 | // Resolve returns what the provided specifier will get resolved to if it was to be imported |
| 100 | // To be used by other parts to get the path |