Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/n-r-w/uniqpool
UniqPool is a wrapper around the worker pool that excludes duplicate tasks
https://github.com/n-r-w/uniqpool
Last synced: 6 days ago
JSON representation
UniqPool is a wrapper around the worker pool that excludes duplicate tasks
- Host: GitHub
- URL: https://github.com/n-r-w/uniqpool
- Owner: n-r-w
- License: mit
- Created: 2024-04-05T22:43:02.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-27T05:49:29.000Z (5 months ago)
- Last Synced: 2024-06-27T06:49:21.772Z (5 months ago)
- Language: Go
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/n-r-w/uniqpool.svg)](https://pkg.go.dev/github.com/n-r-w/uniqpool)
[![Go Coverage](https://github.com/n-r-w/uniqpool/wiki/coverage.svg)](https://raw.githack.com/wiki/n-r-w/uniqpool/coverage.html)
![CI Status](https://github.com/n-r-w/uniqpool/actions/workflows/go.yml/badge.svg)
[![Stability](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
[![Go Report](https://goreportcard.com/badge/github.com/n-r-w/uniqpool)](https://goreportcard.com/badge/github.com/n-r-w/uniqpool)# UniqPool
UniqPool is a wrapper around the worker pool that excludes duplicate tasks.
All incoming tasks first go to the inbound queue, which is processed at a specified interval in FIFO order. If a task with the same identifier is already in the queue, the new task will be ignored.It is useful when you need to process a large number of tasks, part of which can be duplicated.
Internal worker pool is based on .
## Installation
```bash
go get github.com/n-r-w/uniqpool
```## Usage
Here is a basic example of how to use UniqPool:
```go
package mainimport (
"fmt"
"time""github.com/n-r-w/uniqpool"
)func main() {
// 10 - inbound queue capacity
// 5 - workers count
// 100 - worker pool capacity
// time.Second - interval in milliseconds after which incoming tasks will be sent to the worker pool
p := uniqpool.New[string](10, 5, 100, time.Second)p.Submit("task1", func() {
fmt.Println("will be executed")
})p.Submit("task2", func() {
fmt.Println("will be executed")
})p.Submit("task2", func() {
fmt.Println("will not be executed, because the task with the same identifier has already in the queue")
})p.StopAndWait()
}
```