Giter VIP home page Giter VIP logo

rpool's Introduction

RPOOL - routines pool for Golang

Build Status Go Report Card GoDoc Coverage Status

License Apache 2.0

Extension of execution pools over native goroutines on the pure GO.

import "github.com/demdxx/rpool/v2" // Minimal version is Go1.18

Random task pool example

pool := NewPool()
defer pool.Close()

pool.Go(func(){
  atomic.AddInt64(&iterations, 1)
})

Function task pool example

To process some predefined executor over the concurrent queue.

pool := NewPoolFunc(func(arg *int64) {
  atomic.AddInt64(arg, 1)
})
defer pool.Close()

pool.Call(&iterations)

Execute task once at a time

In case of data refreshing we need to execute only one task and no any other until the provious will be completed. All new tasks will be skipet.

datastore := userStore.New()
dataStoreUpdate := NewSinglePoolFunc(func(arg any) {
  datastore.Refresh()
})
defer pool.Close()

...

if !dataStoreUpdate.Call() {
  // Call is ignored because one update task in process
}

Benchmarks

Running tool: go test -benchmem -run=^$ github.com/demdxx/rpool -bench . -v -race

goos: darwin
goarch: arm64
pkg: github.com/demdxx/rpool
Benchmark_PoolFunc
Benchmark_PoolFunc-8              283292              4289 ns/op        0 B/op          0 allocs/op
Benchmark_NoPoolFunc
Benchmark_NoPoolFunc-8             40347             26279 ns/op       46 B/op          2 allocs/op
Benchmark_Pool
Benchmark_Pool-8                   25153             50894 ns/op       24 B/op          1 allocs/op
Benchmark_NoPool
Benchmark_NoPool-8                 31624             32654 ns/op       24 B/op          1 allocs/op
PASS
ok      github.com/demdxx/rpool 5.945s

rpool's People

Contributors

demdxx avatar

Stargazers

Wade Welles avatar

Watchers

 avatar James Cloos avatar  avatar

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.