An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

trylock - TryLock implementation for Go
=======================================

[![Build Status](https://travis-ci.org/LK4D4/trylock.svg?branch=master)](https://travis-ci.org/LK4D4/trylock)
[![GoDoc](https://godoc.org/github.com/LK4D4/trylock?status.svg)](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
}
```