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 @@ ...@@ -10,6 +10,8 @@
package wasm package wasm
import ( import (
"fmt"
"sync/atomic"
"syscall/js" "syscall/js"
"gitlab.com/elixxir/client/v4/bindings" "gitlab.com/elixxir/client/v4/bindings"
...@@ -17,6 +19,8 @@ import ( ...@@ -17,6 +19,8 @@ import (
"gitlab.com/elixxir/wasm-utils/utils" "gitlab.com/elixxir/wasm-utils/utils"
) )
var initializing atomic.Bool
// Cmix wraps the [bindings.Cmix] object so its methods can be wrapped to be // Cmix wraps the [bindings.Cmix] object so its methods can be wrapped to be
// Javascript compatible. // Javascript compatible.
type Cmix struct { type Cmix struct {
...@@ -124,6 +128,7 @@ func NewCmix(_ js.Value, args []js.Value) any { ...@@ -124,6 +128,7 @@ func NewCmix(_ js.Value, args []js.Value) any {
// - Resolves on success. // - Resolves on success.
// - Rejected with an error if creating a new cMix client fails. // - Rejected with an error if creating a new cMix client fails.
func NewSynchronizedCmix(_ js.Value, args []js.Value) any { func NewSynchronizedCmix(_ js.Value, args []js.Value) any {
initializing.Store(true)
ndfJSON := args[0].String() ndfJSON := args[0].String()
storageDir := args[1].String() storageDir := args[1].String()
password := utils.CopyBytesToGo(args[2]) password := utils.CopyBytesToGo(args[2])
...@@ -135,6 +140,7 @@ func NewSynchronizedCmix(_ js.Value, args []js.Value) any { ...@@ -135,6 +140,7 @@ func NewSynchronizedCmix(_ js.Value, args []js.Value) any {
if err != nil { if err != nil {
reject(exception.NewTrace(err)) reject(exception.NewTrace(err))
} else { } else {
initializing.Store(false)
resolve() resolve()
} }
} }
...@@ -196,6 +202,10 @@ func LoadSynchronizedCmix(_ js.Value, args []js.Value) any { ...@@ -196,6 +202,10 @@ func LoadSynchronizedCmix(_ js.Value, args []js.Value) any {
cmixParamsJSON := utils.CopyBytesToGo(args[3]) cmixParamsJSON := utils.CopyBytesToGo(args[3])
promiseFn := func(resolve, reject func(args ...any) js.Value) { 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, net, err := bindings.LoadSynchronizedCmix(storageDir, password,
rs, cmixParamsJSON) rs, cmixParamsJSON)
if err != nil { 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