Skip to content

charithe/timedbuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Timed Buffer

Implementation of a buffer that flushes its' contents immediately when it's full or at regular intervals. This is useful if you have data that you need to buffer but don't want the items to stay in the buffer for too long.

Please note that in some cases it might be more efficient to use the actual data type (and buffer pools) instead of the generic interface{} type used in this implementation.

Usage

go get github.com/charithe/timedbuf

// define a flush function that will be called whenever the buffer is full or the time period has elapsed
func flushFunc(items []interface{}){
    // flush logic
}

// Initialize and use the buffer
tb := timedbuf.New(100, 10 * time.Second, flushFunc)
defer tb.Close()
tb.Put("foo", "bar")
tb.Put("baz")
...

Generics implementation

go get github.com/charithe/timedbuf/v2

// define a flush function that will be called whenever the buffer is full or the time period has elapsed
func flushFunc(items []string){
    // flush logic
}

// Initialize and use the buffer
tb := timedbuf.New(100, 10 * time.Second, flushFunc)
defer tb.Close()
tb.Put("foo", "bar")
tb.Put("baz")
...

About

Go-lang buffer that can be periodically flushed

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages