violin

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

VIOLIN

Go Report Card

Please ... listen.

VIOLIN

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

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
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

Documentation

Index

Constants

View Source
const (
	Name    = "VIOLIN"
	Version = "v0.3.1"
)

BINARY-VIOLIN

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

func WithMaxWorkers

func WithMaxWorkers(max int) Option

WithMaxWorkers set the maximum number of workers

func WithWorkerIdleTimeout

func WithWorkerIdleTimeout(timeout time.Duration) Option

WithWorkerIdleTimeout set the destroyed timeout of idle workers

type Violin

type Violin struct {
	// contains filtered or unexported fields
}

Violin VIOLIN worker pool

func New

func New(opts ...Option) *Violin

New VIOLIN worker pool

func (*Violin) Consume added in v0.2.1

func (v *Violin) Consume(taskC chan func())

Consume the current tasks in the taskC Note: Consume will not execute the tasks which put into the taskC after calling Consume

func (*Violin) ConsumeWait added in v0.2.1

func (v *Violin) ConsumeWait(taskC chan func())

ConsumeWait consume tasks in the taskC and wait for them to complete Note: ConsumeWait will not execute the tasks which put into the taskC after calling ConsumeWait

func (*Violin) IsCleaning

func (v *Violin) IsCleaning() bool

IsCleaning returns true if the worker pool is cleaning (graceful shutdown)

func (*Violin) IsPlaying

func (v *Violin) IsPlaying() bool

IsPlaying returns true if the worker pool is playing (running)

func (*Violin) IsShutdown

func (v *Violin) IsShutdown() bool

IsShutdown returns true if the worker pool is shutdown

func (*Violin) MaxWorkerNum

func (v *Violin) MaxWorkerNum() int

MaxWorkerNum returns the maximum number of workers

func (*Violin) Pause

func (v *Violin) Pause(ctx context.Context)

Pause the worker pool

func (*Violin) Shutdown

func (v *Violin) Shutdown()

Shutdown the worker pool

func (*Violin) ShutdownWait

func (v *Violin) ShutdownWait()

ShutdownWait graceful shutdown, wait for all tasks to complete

func (*Violin) Submit

func (v *Violin) Submit(task func())

Submit a task to the worker pool

func (*Violin) SubmitWait

func (v *Violin) SubmitWait(task func())

SubmitWait submit a task to the worker pool and wait for it to complete

func (*Violin) TaskNum

func (v *Violin) TaskNum() uint32

TaskNum returns the number of tasks

func (*Violin) WaitingTaskNum

func (v *Violin) WaitingTaskNum() int

WaitingTaskNum returns the number of waiting tasks

func (*Violin) WorkerNum

func (v *Violin) WorkerNum() uint32

WorkerNum returns the number of workers

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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