Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/subchen/go-trylock
TryLock support on read-write lock for Golang
https://github.com/subchen/go-trylock
locker mutex trylock
Last synced: about 1 month ago
JSON representation
TryLock support on read-write lock for Golang
- Host: GitHub
- URL: https://github.com/subchen/go-trylock
- Owner: subchen
- License: apache-2.0
- Created: 2018-04-26T06:02:47.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-07T03:38:43.000Z (about 3 years ago)
- Last Synced: 2024-02-28T10:15:38.485Z (3 months ago)
- Topics: locker, mutex, trylock
- Language: Go
- Size: 27.3 KB
- Stars: 33
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go-extra - go-trylock - write lock for Golang|30|9|1|2018-04-26T06:02:47Z|2021-05-07T03:38:43Z| (Goroutines / Advanced Console UIs)
- awesome-go-cn - go-trylock
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go-cn - go-trylock - write 锁。 [![godoc][D]](https://godoc.org/github.com/subchen/go-trylock) (Goroutines / 检索及分析资料库)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- awesome-go-projects - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Standard CLI)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go - go-trylock - write lock for Golang. | - | - | - | (Goroutines / Advanced Console UIs)
- awesome-go-with-framework - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go-cn - go-trylock - write 锁。 [![godoc][D]](https://godoc.org/github.com/subchen/go-trylock) (Goroutines / 检索及分析资料库)
- awesome-go-stars - go-trylock(stars: 34) - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go-cn - go-trylock - write 锁。 ![最近一年没有更新][Yellow] (Goroutines / 高级控制台用户界面)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- awesome-go-with-stars - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- repo-1316-awesome-go-cn - go-trylock - write 锁。 [![godoc][D]](https://godoc.org/github.com/subchen/go-trylock) (Goroutines / 检索及分析资料库)
- repo-1211-awesome-go-cn - go-trylock - write 锁。 [![godoc][D]](https://godoc.org/github.com/subchen/go-trylock) (Goroutines / 检索及分析资料库)
- awesome-go-zh - go-trylock - write 锁。 [![godoc][D]](https://godoc.org/github.com/subchen/go-trylock) (Goroutines / 检索及分析资料库)
- awesome-Char - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- awesome-reader - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- Go-awesome - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go-cn - go-trylock - write lock for Golang.) (Goroutines / Advanced Console UIs)
- awesome-go-handwritten - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. - :arrow_down:0 - :star:4 (Goroutines / Advanced Console UIs)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Advanced Console UIs)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang. (Goroutines / Search and Analytic Databases)
- awesome-go - go-trylock - TryLock support on read-write lock for Golang - ★ 4 (Goroutines)
- go-awesome-cn-star - go-trylock
README
# go-trylock
[![GoDoc](https://godoc.org/github.com/subchen/go-trylock?status.svg)](https://godoc.org/github.com/subchen/go-trylock)
[![Build Status](https://travis-ci.org/subchen/go-trylock.svg?branch=master)](https://travis-ci.org/subchen/go-trylock)
[![Coverage Status](https://coveralls.io/repos/github/subchen/go-trylock/badge.svg?branch=master)](https://coveralls.io/github/subchen/go-trylock?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/subchen/go-trylock)](https://goreportcard.com/report/github.com/subchen/go-trylock)
[![License](http://img.shields.io/badge/License-Apache_2-red.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0)TryLock support on read-write lock for Golang
## Interface
`go-trylock` implements [`sync.Locker`](https://golang.org/src/sync/mutex.go?s=881:924#L21).
Have same interfaces with [`sync.RWMutex`](https://golang.org/src/sync/rwmutex.go?s=987:1319#L18)
Documentation can be found at [Godoc](https://godoc.org/github.com/subchen/go-trylock)
## Examples
```go
import (
"context"
"time"
"errors"
"github.com/subchen/go-trylock/v2"
)var mu = trylock.New()
func goroutineWrite() error {
if ok := mu.TryLock(context.Background()); !ok {
return errors.New("timeout, cannot TryLock !!!")
}
defer mu.Unlock()
// write something
}func goroutineWriteTimeout() error {
if ok := mu.TryLockTimeout(1 * time.Second); !ok {
return errors.New("timeout, cannot TryLock !!!")
}
defer mu.Unlock()
// write something
}func goroutineRead() {
if ok := mu.RTryLock(context.Background()); !ok {
return errors.New("timeout, cannot RTryLock !!!")
}
defer mu.RUnlock()
// read something
}func goroutineReadTimeout() {
if ok := mu.RTryLockTimeout(1 * time.Second); !ok {
return errors.New("timeout, cannot RTryLock !!!")
}
defer mu.RUnlock()
// read something
}
```## LICENSE
Apache 2.0