Skip to content

Commit a060f62

Browse files
authored
Merge pull request #12 from jefft0/fix/setHeadsForGroup-wait-for-_remoteHeads
2 parents 3c755b2 + eb08351 commit a060f62

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

orbitdb.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"berty.tech/go-orbit-db/baseorbitdb"
2727
"berty.tech/go-orbit-db/iface"
2828
"berty.tech/go-orbit-db/pubsub/pubsubcoreapi"
29+
"berty.tech/go-orbit-db/stores"
2930
"berty.tech/weshnet/internal/datastoreutil"
3031
"berty.tech/weshnet/pkg/cryptoutil"
3132
"berty.tech/weshnet/pkg/errcode"
@@ -319,8 +320,28 @@ func (s *BertyOrbitDB) setHeadsForGroup(ctx context.Context, g *protocoltypes.Gr
319320
for i, h := range metaHeads {
320321
metaHeadsEntries[i] = &entry.Entry{Hash: h}
321322
}
323+
324+
if len(metaHeads) == 0 {
325+
return nil
326+
}
327+
328+
chSub, err := metaImpl.EventBus().Subscribe(new(stores.EventReplicated))
329+
if err != nil {
330+
// something is really wrong if this happens, so better return an error
331+
return fmt.Errorf("unable to subscribe to EventReplicated")
332+
}
333+
defer chSub.Close()
334+
335+
// start to load metadata heads
322336
metaImpl.Replicator().Load(ctx, metaHeadsEntries)
323337

338+
// wait for load to finish
339+
select {
340+
case <-chSub.Out():
341+
case <-s.ctx.Done():
342+
return s.ctx.Err()
343+
}
344+
324345
return nil
325346
}
326347

0 commit comments

Comments
 (0)