Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

一个Go语言的连接池库,所有支持Close方法的连接都可以被这个库管理

Notifications You must be signed in to change notification settings

gowithrain/pool

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pool

Pool, written by Go, is a thread safe connection pool. It can be used to manage any connections that implenment pool.Conn interface.

Import

import "github.com/gowithrain/pool"

pool.Conn

pool.Conn is a interface and include Close methond.

type Conn interface {
	Close() error
}

Example

package main

import (
	"github.com/gowithrain/pool"
	"net"
	"time"
)

// in main func
func main() {
	newf := func() (pool.Conn, error) {
		return net.DialTimeout("tcp", "127.0.0.1:8000", time.Duration(1000)*time.Millisecond)
	}
	
	p, err := pool.New(5, 20, newf)
	
	conn, err := p.Get()
	if err != nil {
		// error
		return
	}
	defer conn.Close()
	
	c, ok := conn.Conn.(net.Conn)
	if !ok {
		// error
		return
	}
	
	buf := make([]byte, 10)
	_, err = c.Read(buf)
	if err != nil {
		conn.MarkUseless()
		return
	}
	
	/// do something
	return
}

About

一个Go语言的连接池库,所有支持Close方法的连接都可以被这个库管理

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.