mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-18 18:16:50 +01:00
sdk/dataloader simplify and fix lock issues, now it will work.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
@@ -74,7 +75,8 @@ func (sys *System) batchLoadReplaceableEvents(
|
||||
cm := sync.Mutex{}
|
||||
|
||||
aggregatedContext, aggregatedCancel := context.WithCancel(context.Background())
|
||||
waiting := len(pubkeys)
|
||||
waiting := atomic.Int32{}
|
||||
waiting.Add(int32(len(pubkeys)))
|
||||
|
||||
for i, pubkey := range pubkeys {
|
||||
ctx, cancel := context.WithCancel(ctxs[i])
|
||||
@@ -111,8 +113,7 @@ func (sys *System) batchLoadReplaceableEvents(
|
||||
wg.Done()
|
||||
|
||||
<-ctx.Done()
|
||||
waiting--
|
||||
if waiting == 0 {
|
||||
if waiting.Add(-1) == 0 {
|
||||
aggregatedCancel()
|
||||
}
|
||||
}(i, pubkey)
|
||||
|
||||
Reference in New Issue
Block a user