github.com/micro/go-micro/v2@v2.9.1/util/sync/options.go (about)

     1  package sync
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/micro/go-micro/v2/store"
     7  )
     8  
     9  // Options represents Sync options
    10  type Options struct {
    11  	// Stores represents layers in the sync in ascending order. L0, L1, L2, etc
    12  	Stores []store.Store
    13  	// SyncInterval is the duration between syncs from L0 to L1
    14  	SyncInterval time.Duration
    15  	// SyncMultiplier is the multiplication factor between each store.
    16  	SyncMultiplier int64
    17  }
    18  
    19  // Option sets Sync Options
    20  type Option func(o *Options)
    21  
    22  // Stores sets the layers that make up the sync
    23  func Stores(stores ...store.Store) Option {
    24  	return func(o *Options) {
    25  		o.Stores = make([]store.Store, len(stores))
    26  		for i, s := range stores {
    27  			o.Stores[i] = s
    28  		}
    29  	}
    30  }
    31  
    32  // SyncInterval sets the duration between syncs from L0 to L1
    33  func SyncInterval(d time.Duration) Option {
    34  	return func(o *Options) {
    35  		o.SyncInterval = d
    36  	}
    37  }
    38  
    39  // SyncMultiplier sets the multiplication factor for time to wait each sync layer
    40  func SyncMultiplier(i int64) Option {
    41  	return func(o *Options) {
    42  		o.SyncMultiplier = i
    43  	}
    44  }