Skip to content

rego is a lightweight goroutine pool implementation that controls concurrent resources by reusing goroutines.

License

Notifications You must be signed in to change notification settings

alilestera/rego

Repository files navigation

rego means recycle goroutines and reduce goroutines

Introduction

Library rego is a lightweight goroutine pool implementation that controls concurrent resources by reusing goroutines. Developers can significantly reduce memory growth in concurrent programs with minimal performance trade-offs.

Install

go get -u github.com/alilestera/rego

Quick Start

Instantiate with customize capacity

You need to call rego.New to instantiate a Rego with a given capacity:

r := rego.New(100)

Submit tasks

You can call r.Submit() submit tasks:

r.Submit(func() {})

Release

If you need to close Rego:

r.Release() // close Rego and ignore all waiting tasks

or

r.ReleaseWait() // close Rego and wait all tasks done

Example

package main

import (
	"fmt"

	"github.com/alilestera/rego"
)

func main() {
	r := rego.New(100)
	r.Submit(func() {
		fmt.Println("hello world")
	})
	r.ReleaseWait()
}

Configuration options

Option Default Description
WithMinWorkers 0 Set the minimum number of active workers
WithIdleTimeout 2 * time.Second Set the idle timeout of active worker

Example

r := rego.New(100, rego.WithMinWorkers(10), rego.WithIdleTimeout(5*time.Second))

Acknowledgments

This project was inspired by or benefited from the following repositories:

License

The source code in rego is licensed under Apache License 2.0.

About

rego is a lightweight goroutine pool implementation that controls concurrent resources by reusing goroutines.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages