chanlock

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package chanlock 基于chan实现trylock乐观锁

Index

Constants

This section is empty.

Variables

View Source
var DefaultLockTimeout = 10 * time.Millisecond

DefaultLockTimeout 默认加锁超时时间20ms就认为加锁失败

Functions

This section is empty.

Types

type ChanLock

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

ChanLock chan lock

func NewChanLock

func NewChanLock() *ChanLock

NewChanLock 实例化一个通道空结构体锁对象

func (*ChanLock) Lock

func (l *ChanLock) Lock()

Lock 通道加锁,如果无法放入ch,该方法就会阻塞,直到ch通道锁释放为止

func (*ChanLock) TryLock

func (l *ChanLock) TryLock(timeout ...time.Duration) bool

TryLock 乐观锁实现

func (*ChanLock) Unlock

func (l *ChanLock) Unlock()

Unlock实现通道解锁

Jump to

Keyboard shortcuts

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