sync

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchWriter

type BatchWriter struct {
	// contains filtered or unexported fields
}

BatchWriter is a struct that wraps a concurrent sync.Map and dispatches all writes to it at once, a specific duration (e.g. 1s) after the last write was performed. This allows for 100s of concurrent writes in milliseconds to the same map in one sending goroutine; and one receiving goroutine which can process the result after all the writes are done.

func NewBatchWriter

func NewBatchWriter(duration time.Duration) *BatchWriter

NewBatchWriter creates a new BatchWriter

func (*BatchWriter) Close

func (b *BatchWriter) Close()

Close closes the underlying channel

func (*BatchWriter) Load

func (b *BatchWriter) Load(key interface{}) (value interface{}, ok bool)

Load reads the key from the map

func (*BatchWriter) ProcessBatch

func (b *BatchWriter) ProcessBatch(fn func(key, val interface{}) bool) bool

ProcessBatch is effectively a Range over the sync.Map, once a batch write is released. This should be used in the receiving goroutine. The internal map is reset after this call, so be sure to capture all the contents if needed. This function returns false if Close() has been called.

func (*BatchWriter) Store

func (b *BatchWriter) Store(key, value interface{})

Store writes the value for the specified key to the map If no other .Store call is made during the specified duration, flushCh is invoked and ProcessBatch unblocks in the other goroutine

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor is a convenience wrapper around starting a goroutine with a wait group, which can be used to wait for the goroutine to stop.

func RunMonitor

func RunMonitor(f func()) (m *Monitor)

func (*Monitor) Wait

func (m *Monitor) Wait()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL