gxsync

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2018 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Overview

ref: https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/

Package gxsync provides some synchronization primitives such as trylock & semaphore.

this file provides a kind of unbouned channel

Index

Constants

View Source
const (
	QSize = 64
)

Variables

View Source
var (
	ErrBroadcastClosed = fmt.Errorf("broadcast closed!")
)

Functions

This section is empty.

Types

type Broadcaster

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

func NewBroadcaster

func NewBroadcaster() Broadcaster

create a new broadcaster object.

func (Broadcaster) Close

func (b Broadcaster) Close()

func (Broadcaster) Listen

func (b Broadcaster) Listen() Receiver

start listening to the nodes.

func (Broadcaster) Write

func (b Broadcaster) Write(value interface{}) (rerr error)

Node a value to all listeners.

type Empty

type Empty struct{}

type Node

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

type Receiver

type Receiver struct {
	C chan Node
}

func (*Receiver) Read

func (r *Receiver) Read() (interface{}, error)

read a value that has been broadcast, waiting until one is available if necessary.

func (*Receiver) ReadChan

func (r *Receiver) ReadChan() chan Node

func (*Receiver) ReadDone

func (r *Receiver) ReadDone(n Node) (interface{}, error)

type Semaphore

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

func NewSemaphore

func NewSemaphore(parallelNum int) *Semaphore

func (*Semaphore) Post

func (s *Semaphore) Post()

func (*Semaphore) TimeWait

func (s *Semaphore) TimeWait(timeout int) bool

@timeout is in nanoseconds

func (*Semaphore) TryWait

func (s *Semaphore) TryWait() bool

func (*Semaphore) Wait

func (s *Semaphore) Wait()

type TryLock

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

func NewTryLock

func NewTryLock() *TryLock

func (*TryLock) Lock

func (l *TryLock) Lock()

func (*TryLock) Trylock

func (l *TryLock) Trylock() bool

func (*TryLock) Unlock

func (l *TryLock) Unlock()

type UnboundedChan

type UnboundedChan struct {

	// Q      *gxqueue.Queue
	Q *gxdeque.Deque
	// contains filtered or unexported fields
}

refer from redisgo/redis/pool.go

func NewUnboundedChan

func NewUnboundedChan() *UnboundedChan

func (*UnboundedChan) Close

func (q *UnboundedChan) Close()

func (*UnboundedChan) Len

func (q *UnboundedChan) Len() int

func (*UnboundedChan) Pop

func (q *UnboundedChan) Pop() interface{}

func (*UnboundedChan) Push

func (q *UnboundedChan) Push(v interface{})

func (*UnboundedChan) SetWaitOption

func (q *UnboundedChan) SetWaitOption(wait bool)

在pop时,如果没有资源,是否等待 即使用乐观锁还是悲观锁

func (*UnboundedChan) TryPop

func (q *UnboundedChan) TryPop() (interface{}, bool)

Directories

Path Synopsis
Package pool implements a pool of Object interfaces to manage and reuse them.
Package pool implements a pool of Object interfaces to manage and reuse them.

Jump to

Keyboard shortcuts

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