Giter VIP home page Giter VIP logo

batch's Introduction

batch

License GoDoc travis Go Report Card coveralls

仅支持Go 1.18及以上版本, 因为泛型的原因。

批处理一组元素,或者等待一定的时间。

一旦元素达到设定的阈值,就进行处理,否则调用者就阻塞等待。

如果没有充足的元素需要处理,那么会把既有的元素处理完毕后继续等待.

如果设置了timeout,即使还没有达到设定的阈值,也会进行批处理。

使用这个库既可以避免CPU的无谓空转,也可以有效的进行成批数据的处理。

使用方法

    in := make(chan int, 100)
	go func() {
        for {
            // 往in中塞数据
            ......
        }
		
	}()

	
	Batch(in, 80, func(items []int) {
		// 处理一批数据
	})

batch's People

Contributors

smallnest avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

daheige

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.