• Stars
    star
    33
  • Rank 757,352 (Top 16 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TryLock support on read-write lock for Golang

go-trylock

GoDoc Build Status Coverage Status Go Report Card License

TryLock support on read-write lock for Golang

Interface

go-trylock implements sync.Locker.

Have same interfaces with sync.RWMutex

Documentation can be found at Godoc

Examples

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

More Repositories

1

jetbrick-template-2x

Template Engine for Java
Java
371
star
2

frep

Generate file using template from environment, arguments, json/yaml/toml config files
Go
154
star
3

javadoc.chm

This software generates an Microsoft HTML Help(CHM) from generic javadoc style API documents
Java
143
star
4

angular-async-loader

Load modules and components asynchronously for angular 1.x application.
JavaScript
136
star
5

jetbrick-template-1x

Java template engine, quickly and easily.
Java
68
star
6

go-xmldom

XML DOM processing for Golang, supports xpath query
Go
44
star
7

jetbrick-webmvc

jetbrick web mvc framework
Java
25
star
8

centos-7-kickstart

build a centos 7 iso/ovf/ova with kickstart
Shell
21
star
9

jetbrick-commons

jetbrick utility classes
Java
21
star
10

go-log

Simple and configurable Logging in Go, with level, formatters and writers
Go
14
star
11

go-cli

A full-featured and easy to use command-line package
Go
13
star
12

jetbrick-template-2x-samples

Samples for jetbrick-template-2x
Java
11
star
13

jetbrick-template-1x-samples

The samples for jetbrick-template integrated with webmvc
Java
9
star
14

jetbrick-ioc

IoC framwork for jetbrick
Java
7
star
15

jetbrick-webmvc-samples

Samples for jetbrick-webmvc
Java
6
star
16

go-stack

Common utility functions for Golang
Go
6
star
17

go-tableify

Pretty console printing of tabular data
Go
5
star
18

go-curl

A Go HTTP client library for creating and sending API requests
Go
5
star
19

hello-algorithm

🌍 🌎 东半球最酷的学习项目 | 包括:1、我写的三十万字图解算法题典 2、100 张各语言思维导图 和 1000 本编程电子📚 3、100 篇大厂面经下载 | English version supported !!! 国人项目上榜不易,右上角助力一波 🚀🚀!干就对了,奥利给 !💪💪💪
Java
4
star
20

jetbrick-orm

Object-relational mapping framework
Java
4
star
21

jetbrick-all-1x

A full-stack framework written with java
Java
4
star
22

gls

A goroutine-local storage for golang
Go
3
star
23

subchen.github.io

WebSite for subchen.github.com
HTML
3
star
24

ovfenv-installer

Configure networking from vSphere ovfEnv properties
Go
3
star
25

homebrew-tap

Tools of macOS Homebrew Packages
Ruby
2
star
26

snack

Generic functional library for javascript/node.js
JavaScript
2
star
27

snack-string

Generic string functional library for javascript/node.js
JavaScript
2
star
28

dev-box

A development box deployer, Support macOS, CentOS and Ubuntu.
Shell
2
star
29

shaft

Java simple database operation framework
Java
2
star
30

snack-cli

command-line interfaces for node.js
JavaScript
2
star
31

bintray-cli

Command line for api.bintray.com
1
star
32

jetbrick-template-shiro

Shiro tag extension for jetbrick-template
Java
1
star
33

jetbrick-website-app

website for http://subchen.github.io/
Java
1
star
34

jetbrick-extension

jetbrick extension modules
Java
1
star
35

jetbrick-jdbclog

jdbc logger for jetbrick
Java
1
star
36

jetbrick-ioc-spring

Spring intergrate for Jetbrick IoC
Java
1
star