Skip to content
Snippets Groups Projects
Commit d4b14c6e authored by Jono Wenger's avatar Jono Wenger
Browse files

Document initializing atomic.bool in cmix.go and fix logic

parent 552a26bd
Branches
Tags
1 merge request!109Project/haven beta
......@@ -19,6 +19,8 @@ import (
"gitlab.com/elixxir/wasm-utils/utils"
)
// initializing prevents a synchronized Cmix object from being loaded while one
// is being initialized.
var initializing atomic.Bool
// Cmix wraps the [bindings.Cmix] object so its methods can be wrapped to be
......@@ -128,19 +130,23 @@ 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])
rs := newRemoteStore(args[3])
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := bindings.NewSynchronizedCmix(ndfJSON, storageDir,
password, rs)
// Block loading of synchronized Cmix during initialisation
initializing.Store(true)
err := bindings.NewSynchronizedCmix(ndfJSON, storageDir, password, rs)
// Unblock loading of synchronized Cmix during initialisation
initializing.Store(false)
if err != nil {
reject(exception.NewTrace(err))
} else {
initializing.Store(false)
resolve()
}
}
......@@ -238,8 +244,7 @@ func (c *Cmix) GetReceptionID(js.Value, []js.Value) any {
//
// Returns a promise:
// - Resolves with the RemoteKV object.
func (c *Cmix) GetRemoteKV(_ js.Value, args []js.Value) any {
func (c *Cmix) GetRemoteKV(js.Value, []js.Value) any {
promiseFn := func(resolve, reject func(args ...any) js.Value) {
kv := c.api.GetRemoteKV()
resolve(newRemoteKvJS(kv))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment