Skip to content

Commit

Permalink
Execute transactions in go routines concurrently
Browse files Browse the repository at this point in the history
Signed-off-by: Stanislav Jakuschevskij <[email protected]>
  • Loading branch information
twoGiants committed Jan 3, 2025
1 parent 36f8be7 commit f465eb8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions off_chain_data/application-go/transact.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"sync"

atb "offChainData/contract"
"offChainData/utils"
Expand Down Expand Up @@ -35,16 +36,23 @@ func newTransactApp(smartContract *atb.AssetTransferBasic) *transactApp {
}

func (t *transactApp) run() {
var wg sync.WaitGroup

for i := 0; i < t.batchSize; i++ {
t.transact()
wg.Add(1)
go func() {
defer wg.Done()
t.transact()
}()
}

wg.Wait()
}

func (t *transactApp) transact() {
anAsset := atb.NewAsset()

t.smartContract.CreateAsset(anAsset)
// TODO print txID to compare easier with block processing
fmt.Println("Created asset", anAsset.ID)

// Transfer randomly 1 in 2 assets to a new owner.
Expand Down

0 comments on commit f465eb8

Please sign in to comment.