Skip to content

Files

Latest commit

Apr 19, 2016
c0e5b5b · Apr 19, 2016

History

History
24 lines (18 loc) · 651 Bytes

README.md

File metadata and controls

24 lines (18 loc) · 651 Bytes

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

Usage

type LockedStruct struct {
	mu trylock.Mutex
}

storage := &LockedStruct{}

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