Popularity
2.7
Stable
Activity
0.0
Stable
33
3
9

Programming language: Go
License: Apache License 2.0
Tags: Goroutines    
Latest version: v2.0.0

go-trylock alternatives and similar packages

Based on the "Goroutines" category.
Alternatively, view go-trylock alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of go-trylock or a related project?

Add another 'Goroutines' Package

README

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


*Note that all licence references and agreements mentioned in the go-trylock README section above are relevant to that project's source code only.