# go-trylock **Repository Path**: mirrors_subchen/go-trylock ## Basic Information - **Project Name**: go-trylock - **Description**: TryLock support on read-write lock for Golang - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-18 - **Last Updated**: 2026-05-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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