Git Product home page Git Product logo

batcher's Introduction

batcher

Godoc Go Report Card

Package batcher provides mechanism to perform batch operation.

Inspired by go-batcher.

Install

go get github.com/aperdana/batcher

Usage

Below is an example on how to use batcher. Do check out godoc reference for more info.

package main

import (
	"fmt"
	"time"

	"github.com/aperdana/batcher"
)

func main() {
	// Create a new Batcher
	b := batcher.New(func(batched []interface{}) {
		if len(batched) > 0 {
			fmt.Printf("Here's the batched items: %v\n", batched)
		}
	}, 100*time.Millisecond)

	// Starts listening for items
	b.Listen()

	// Batch item
	b.Batch("I")
	b.Batch("Am")
	b.Batch("A")
	b.Batch("Gopher")

	time.Sleep(110 * time.Millisecond)

	b.Batch("2nd batch")

	time.Sleep(100 * time.Millisecond)

	// Output:
	// Here's the batched items: [I Am A Gopher]
	// Here's the batched items: [2nd batch]
}

batcher's People

Contributors

aperdana avatar

Stargazers

Aloysius Michael Tansy avatar  avatar

Watchers

 avatar

batcher's Issues

Graceful Shutdown

Batcher needs to be able to shutdown gracefully, meaning it is able to:

  • Receive Stop signal
  • Process buffered items, blocks until it's done
  • Exit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.