Skip to content

Commit 0f4fbe6

Browse files
committed
Alternative: Register mapper function of options instead of just the extra options
The solution described in comment coinbase#423 (comment). It mostly demonstrates that it adds too much complexity for what it gains.
1 parent 7942ab4 commit 0f4fbe6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

statefulsyncer/configuration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func WithSeenConcurrency(concurrency int64) Option {
6969
}
7070
}
7171

72-
func WithExtraSyncerOpts(os ...syncer.Option) Option {
72+
func WithCustomSyncerOpts(mapper func(...syncer.Option) []syncer.Option) Option {
7373
return func(s *StatefulSyncer) {
74-
s.extraSyncerOpts = os
74+
s.mapSyncerOpts = mapper
7575
}
7676
}

statefulsyncer/stateful_syncer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type StatefulSyncer struct {
7373
seenSemaphore *semaphore.Weighted
7474
seenSemaphoreSize int64
7575

76-
extraSyncerOpts []syncer.Option
76+
mapSyncerOpts func(...syncer.Option) []syncer.Option
7777
}
7878

7979
// Logger is used by the statefulsyncer to
@@ -164,12 +164,12 @@ func (s *StatefulSyncer) Sync(ctx context.Context, startIndex int64, endIndex in
164164
s,
165165
s,
166166
s.cancel,
167-
append([]syncer.Option{
167+
s.mapSyncerOpts(
168168
syncer.WithPastBlocks(pastBlocks),
169169
syncer.WithCacheSize(s.cacheSize),
170170
syncer.WithMaxConcurrency(s.maxConcurrency),
171171
syncer.WithAdjustmentWindow(s.adjustmentWindow),
172-
}, s.extraSyncerOpts...)...,
172+
)...,
173173
)
174174

175175
return syncer.Sync(ctx, startIndex, endIndex)

0 commit comments

Comments
 (0)