项目作者: tcfw

项目描述 :
Chan based queue worker
高级语言: Go
项目地址: git://github.com/tcfw/go-queue.git
创建时间: 2018-10-22T02:23:04Z
项目社区:https://github.com/tcfw/go-queue

开源协议:MIT License

下载


Go-Queue

PkgGoDev
Go Report Card

A simple generic chan based queue worker

License

Please refer to LICENSE.md

Examples

Simple example

  1. package main
  2. import (
  3. queue "github.com/tcfw/go-queue"
  4. )
  5. type Processor struct {}
  6. func (p *Processor) Handle(job interface{}) {
  7. //Handle job...
  8. }
  9. func main() {
  10. processor := &Processor{}
  11. dispatcher := queue.NewDispatcher(processor)
  12. dispatcher.Run()
  13. }

Specify number of workers

  1. package main
  2. import (
  3. queue "github.com/tcfw/go-queue"
  4. )
  5. type Processor struct {}
  6. func (p *Processor) Handle(job interface{}) {
  7. //Handle job...
  8. }
  9. func main() {
  10. processor := &Processor{}
  11. dispatcher := queue.NewDispatcher(processor)
  12. //20 workers will be created
  13. dispatcher.MaxWorkers = 20
  14. dispatcher.Run()
  15. }