go-unique-queue

module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2021 License: Apache-2.0

README

Introduction

We define a queue with unique keys.

When pushing, it checks if the queue has the same key. If there is, the value will be updated, and the key is not re-queued.

When poping, it gets the latest value and executes the custom workFunc defined by yourself.

Required

Go 1.15

Start

  go get github.com/MrOnepiece/go-unique-queue

Example


func workFunc(obj interface{}) error {
  fmt.Println(obj.(string))
}

func main() {
  // parameters:
  // capacity: the queue capacity
  // worker: the number of worker
  // workFunc: when pop, the worker will execute the work function
  // onSuccess: when workFunc execute succeed, the onSuccess func will be executed
  // onFailed: when workFunc execute failed, the onFailed func will be executed
  // stopCh:the stop signal

  q := queue.NewQueue(100, 5, workFunc, nil, nil, nil)
  go q.Run()
  
  key := "test"
  s := "hello world"
  q.Push(key, s)
  time.Sleep(10 * time.Second)

}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL