Skip to content

Commit

Permalink
Merge pull request #12 from jefft0/fix/setHeadsForGroup-wait-for-_rem…
Browse files Browse the repository at this point in the history
…oteHeads
  • Loading branch information
gfanton authored Feb 23, 2023
2 parents 3c755b2 + eb08351 commit a060f62
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions orbitdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"berty.tech/go-orbit-db/baseorbitdb"
"berty.tech/go-orbit-db/iface"
"berty.tech/go-orbit-db/pubsub/pubsubcoreapi"
"berty.tech/go-orbit-db/stores"
"berty.tech/weshnet/internal/datastoreutil"
"berty.tech/weshnet/pkg/cryptoutil"
"berty.tech/weshnet/pkg/errcode"
Expand Down Expand Up @@ -319,8 +320,28 @@ func (s *BertyOrbitDB) setHeadsForGroup(ctx context.Context, g *protocoltypes.Gr
for i, h := range metaHeads {
metaHeadsEntries[i] = &entry.Entry{Hash: h}
}

if len(metaHeads) == 0 {
return nil
}

chSub, err := metaImpl.EventBus().Subscribe(new(stores.EventReplicated))
if err != nil {
// something is really wrong if this happens, so better return an error
return fmt.Errorf("unable to subscribe to EventReplicated")
}
defer chSub.Close()

// start to load metadata heads
metaImpl.Replicator().Load(ctx, metaHeadsEntries)

// wait for load to finish
select {
case <-chSub.Out():
case <-s.ctx.Done():
return s.ctx.Err()
}

return nil
}

Expand Down

0 comments on commit a060f62

Please sign in to comment.