From b3a6c964012cee9e57524b54105ead9f7518b6d4 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 29 Jun 2024 11:23:03 +0530 Subject: [PATCH] remove sleep in add web workers and return bool in createWorkers --- wasmsdk/blobber.go | 8 ++++---- wasmsdk/cache.go | 15 +++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 9793c3000..e5beeb7cc 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -629,7 +629,7 @@ func multiUpload(jsonBulkUploadOptions string) (MultiUploadResult, error) { result.Success = false return result, errors.New("Error fetching the allocation") } - addWebWorkers(allocationObj) + operationRequests := make([]sdk.OperationRequest, n) for idx, option := range options { wg := &sync.WaitGroup{} @@ -1019,12 +1019,12 @@ func terminateWorkersWithAllocation(alloc *sdk.Allocation) { } } -func createWorkers(allocationID string) { +func createWorkers(allocationID string) bool { alloc, err := getAllocation(allocationID) if err != nil { - return + return false } - addWebWorkers(alloc) + return addWebWorkers(alloc) } func startListener() error { diff --git a/wasmsdk/cache.go b/wasmsdk/cache.go index 051b90595..d6ef7b76e 100644 --- a/wasmsdk/cache.go +++ b/wasmsdk/cache.go @@ -6,7 +6,6 @@ package main import ( "time" - "github.com/0chain/gosdk/core/sys" "github.com/0chain/gosdk/wasmsdk/jsbridge" "github.com/0chain/gosdk/zboxcore/client" "github.com/0chain/gosdk/zboxcore/sdk" @@ -67,17 +66,17 @@ func reloadAllocation(allocationID string) (*sdk.Allocation, error) { return it.Allocation, nil } -func addWebWorkers(alloc *sdk.Allocation) { +func addWebWorkers(alloc *sdk.Allocation) (isCreated bool) { c := client.GetClient() if c == nil || len(c.Keys) == 0 { return } - isCreated := false + for _, blober := range alloc.Blobbers { - _, isCreated, _ = jsbridge.NewWasmWebWorker(blober.ID, blober.Baseurl, c.ClientID, c.Keys[0].PublicKey, c.Keys[0].PrivateKey, c.Mnemonic) //nolint:errcheck - } - // wait for worker to be instantiated - if isCreated { - sys.Sleep(1 * time.Second) + _, workerCreated, _ := jsbridge.NewWasmWebWorker(blober.ID, blober.Baseurl, c.ClientID, c.Keys[0].PublicKey, c.Keys[0].PrivateKey, c.Mnemonic) //nolint:errcheck + if workerCreated { + isCreated = true + } } + return }