The time driven batch queue
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
.travis.yml
LICENSE
README.md
tempo.go
tempo_test.go

README.md

tempo Go Report Card Build Status GoDoc Reference

A dispatched batch queue to process items at time intervals or when a batching limit is met.

Features

  • Non-blocking enqueue
    Queue up incoming items without blocking processing.

  • Dispatching by periodic time intervals
    Set a time interval and get batched items after time expires.

  • Dispatching as soon as a batch limit is met
    If a batch is filled before the time interval is up, dispatching is handled immediately.

  • Plain old Go channels
    Implementation relies heavily on channels and is free of mutexes and other bookkeeping techniques.

3s demo

Install

$ dep ensure -add github.com/ef2k/tempo

Documentation

https://godoc.org/github.com/ef2k/tempo

Sample Usage

Dispatch a batch at 10 second intervals or as soon as a batching limit of 50 items is met. See examples/ for working code.

// initialize
d := tempo.NewDispatcher(&tempo.Config{
  Interval:      time.Duration(10) * time.Second,
  MaxBatchItems: 50,
})
defer d.Stop()
go d.Start()

// produce some messages
go func() {
  for i:= 0; i < 100; i++ {
    m := fmt.Sprintf("message #%d", i)
    d.Q<-m
  }
}()

// consume the batch
for {
  select {
    case batch := <-d.Batch:
      for _, b := range batch {
        s := b.(string)
        // do whatever.
        log.Print(s)
      }
  }
}

Contribute

Improvements, fixes, and feedback are welcome.

Legal

MIT license.