GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - wind-c/bqueue: Time driven non-blocking and high-performance batch queue

BranchesTags
Open more actions menu

Latest commit

 

History

8 Commits
8 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
bqueue.go
bqueue.go
 
 
bqueue_test.go
bqueue_test.go
 
 
go.mod
go.mod
 
 

Repository files navigation

bqueue Go Report Card Build Status GoDoc Reference

A high-performance batch queue to process items at time intervals or when a batching limit is met.
It is implemented using the go standard library and does not import any third-party libraries.

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.

  • Supports channel and callback
    You can read the OutQueue channel to get batch items, or you can use callback function. See Examples for details.

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

Install

$ go get -u github.com/wind-c/bqueue

Sample Usage

Dispatch a batch at 1 second intervals or as soon as a batching limit of 64 items is met, if the number of messages is large, increase MaxQueueSize. See examples/ for working code.

import (
  "fmt"
  "log"
  "time"
  "github.com/wind-c/bqueue"
)

// initialize
b := bqueue.NewBatchQueue(&bqueue.Options{
  Interval:      time.Duration(1) * time.Second,
  MaxBatchItems: 64,
  MaxQueueSize:  1024,
})
defer b.Stop()
go b.Start()

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

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

Contribute

Improvements, fixes, and feedback are welcome.

Legal

MIT license.

About

Time driven non-blocking and high-performance batch queue

Topics

batchcallback-functionschannelcontextgolanghigh-performancenon-blockingqueuetimer

Resources

Readme
MIT license
Activity

Stars

6 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.