Skip to content
Snippets Groups Projects
Commit 69b0cc3f authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Add a guard, don't allow loads when New is running

parent 34ab9a77
No related branches found
No related tags found
1 merge request!109Project/haven beta
......@@ -10,6 +10,8 @@
package wasm
import (
"fmt"
"sync/atomic"
"syscall/js"
"gitlab.com/elixxir/client/v4/bindings"
......@@ -17,6 +19,8 @@ import (
"gitlab.com/elixxir/wasm-utils/utils"
)
var initializing atomic.Bool
// Cmix wraps the [bindings.Cmix] object so its methods can be wrapped to be
// Javascript compatible.
type Cmix struct {
......@@ -124,6 +128,7 @@ func NewCmix(_ js.Value, args []js.Value) any {
// - Resolves on success.
// - Rejected with an error if creating a new cMix client fails.
func NewSynchronizedCmix(_ js.Value, args []js.Value) any {
initializing.Store(true)
ndfJSON := args[0].String()
storageDir := args[1].String()
password := utils.CopyBytesToGo(args[2])
......@@ -135,6 +140,7 @@ func NewSynchronizedCmix(_ js.Value, args []js.Value) any {
if err != nil {
reject(exception.NewTrace(err))
} else {
initializing.Store(false)
resolve()
}
}
......@@ -196,6 +202,10 @@ func LoadSynchronizedCmix(_ js.Value, args []js.Value) any {
cmixParamsJSON := utils.CopyBytesToGo(args[3])
promiseFn := func(resolve, reject func(args ...any) js.Value) {
if initializing.Load() {
reject(exception.NewTrace(fmt.Errorf(
"cannot Load when New is running")))
}
net, err := bindings.LoadSynchronizedCmix(storageDir, password,
rs, cmixParamsJSON)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment