trylock

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2018 License: MIT Imports: 3 Imported by: 29

README

trylock - TryLock implementation for Go

Build Status GoDoc

trylock uses unsafe, which is sorta "unsafe", but should work until sync.Mutex will change its layout (I hope it never will).

The original author of trylock is by LK4D4.

Usage

type LockedStruct struct {
	trylock.Mutex
}

storage := &LockedStruct{}

if storage.TryLock() {
	// do something with storage
} else {
	// return busy or use some logic for unavailable storage
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

type Mutex struct {
	sync.Mutex
}

Mutex is sync.Mutex with the ability to try to Lock.

func (*Mutex) TryLock

func (m *Mutex) TryLock() bool

TryLock tries to lock the Mutex. It returns true in case of success, false otherwise.

Jump to

Keyboard shortcuts

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