https://github.com/LK4D4/trylock
TryLock for Go
https://github.com/LK4D4/trylock
go mutex sync
Last synced: about 1 year ago
JSON representation
TryLock for Go
- Host: GitHub
- URL: https://github.com/LK4D4/trylock
- Owner: LK4D4
- License: mit
- Created: 2016-04-19T16:10:24.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-10-27T06:53:49.000Z (over 6 years ago)
- Last Synced: 2024-11-19T01:42:43.788Z (over 1 year ago)
- Topics: go, mutex, sync
- Language: Go
- Size: 5.86 KB
- Stars: 66
- Watchers: 2
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
trylock - TryLock implementation for Go
=======================================
[](https://travis-ci.org/LK4D4/trylock)
[](https://godoc.org/github.com/LK4D4/trylock)
trylock uses unsafe, which is sorta "unsafe", but should work until `sync.Mutex`
will change its layout (I hope it never will).
# Usage
```go
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
}
```