Skip to content

B1NARY-GR0UP/violin

Repository files navigation

VIOLIN

VIOLIN worker pool / connection pool, rich APIs and configuration options are provided.

Go Report Card

Install

go get github.com/B1NARY-GR0UP/violin

Quick Start

Worker Pool

package main

import (
	"fmt"

	"github.com/B1NARY-GR0UP/violin"
)

func main() {
	v := violin.New()
	defer v.Shutdown()
	v.Submit(func() {
		fmt.Println("Hello, VIOLIN!")
	})
}

Connection Pool

package main

import (
	"net"
	"time"

	"github.com/B1NARY-GR0UP/violin/cool"
)

func main() {
	producer := func() (net.Conn, error) {
		return net.Dial("your-network", "your-address")
	}
	c, _ := cool.New(5, 30, producer, cool.WithConnIdleTimeout(30*time.Second))
	defer c.Close()
	_ = c.Len()
	conn, _ := c.Get()
	_ = conn.Close()
	if cc, ok := conn.(*cool.Conn); ok {
		cc.MarkUnusable()
		if cc.IsUnusable() {
			_ = cc.Close()
		}
	}
}

Configuration

Worker Pool

Option Default Description
WithMinWorkers 0 Set the minimum number of workers
WithMaxWorkers 5 Set the maximum number of workers
WithWorkerIdleTimeout 3 * time.Second Set the destroyed timeout of idle workers

Connection Pool

Option Default Description
WithConnIdleTimeout 0 Set the connection idle timeout

Blogs

Credits

Sincere appreciation to the following repositories that made the development of VIOLIN possible.

License

VIOLIN is distributed under the Apache License 2.0. The licenses of third party dependencies of VIOLIN are explained here.

ECOLOGY

BMS

VIOLIN is a Subproject of the Basic Middleware Service