Skip to content

Commit

Permalink
Alternative: Register mapper function of options instead of just the …
Browse files Browse the repository at this point in the history
…extra options

The solution described in comment coinbase#423 (comment). It mostly demonstrates that it adds too much complexity for what it gains.
  • Loading branch information
bisgardo committed Sep 10, 2022
1 parent 7942ab4 commit 0f4fbe6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions statefulsyncer/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func WithSeenConcurrency(concurrency int64) Option {
}
}

func WithExtraSyncerOpts(os ...syncer.Option) Option {
func WithCustomSyncerOpts(mapper func(...syncer.Option) []syncer.Option) Option {
return func(s *StatefulSyncer) {
s.extraSyncerOpts = os
s.mapSyncerOpts = mapper
}
}
6 changes: 3 additions & 3 deletions statefulsyncer/stateful_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type StatefulSyncer struct {
seenSemaphore *semaphore.Weighted
seenSemaphoreSize int64

extraSyncerOpts []syncer.Option
mapSyncerOpts func(...syncer.Option) []syncer.Option
}

// Logger is used by the statefulsyncer to
Expand Down Expand Up @@ -164,12 +164,12 @@ func (s *StatefulSyncer) Sync(ctx context.Context, startIndex int64, endIndex in
s,
s,
s.cancel,
append([]syncer.Option{
s.mapSyncerOpts(
syncer.WithPastBlocks(pastBlocks),
syncer.WithCacheSize(s.cacheSize),
syncer.WithMaxConcurrency(s.maxConcurrency),
syncer.WithAdjustmentWindow(s.adjustmentWindow),
}, s.extraSyncerOpts...)...,
)...,
)

return syncer.Sync(ctx, startIndex, endIndex)
Expand Down

0 comments on commit 0f4fbe6

Please sign in to comment.