Skip to content
Snippets Groups Projects
Select Git revision
  • 99a23614100fdb041e42c7929582f29b903fc579
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

go.mod

Blame
  • This project manages its dependencies using Go Modules. Learn more
    options.go 1.07 KiB
    package batchworkerpool
    
    import (
    	"runtime"
    	"time"
    )
    
    var DEFAULT_OPTIONS = &Options{
    	WorkerCount:            2 * runtime.NumCPU(),
    	QueueSize:              2 * runtime.NumCPU() * 64,
    	BatchSize:              64,
    	BatchCollectionTimeout: 15 * time.Millisecond,
    }
    
    func WorkerCount(workerCount int) Option {
    	return func(args *Options) {
    		args.WorkerCount = workerCount
    	}
    }
    
    func BatchSize(batchSize int) Option {
    	return func(args *Options) {
    		args.BatchSize = batchSize
    	}
    }
    
    func BatchCollectionTimeout(batchCollectionTimeout time.Duration) Option {
    	return func(args *Options) {
    		args.BatchCollectionTimeout = batchCollectionTimeout
    	}
    }
    
    func QueueSize(queueSize int) Option {
    	return func(args *Options) {
    		args.QueueSize = queueSize
    	}
    }
    
    type Options struct {
    	WorkerCount            int
    	QueueSize              int
    	BatchSize              int
    	BatchCollectionTimeout time.Duration
    }
    
    func (options Options) Override(optionalOptions ...Option) *Options {
    	result := &options
    	for _, option := range optionalOptions {
    		option(result)
    	}
    
    	return result
    }
    
    type Option func(*Options)