Skip to content

A Golang utility package which provides a way to lock a set of keys so that any subsequent call with a non-empty subset of already locked keys makes the goroutine waiting.

License

Notifications You must be signed in to change notification settings

yarspirin/keylock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

keylock

Build Status

A Golang utility package which provides a way to lock a set of keys so that any subsequent call with a non-empty subset of already locked keys makes the goroutine waiting.

Usage

l := keylock.New()

canceled, unlock := l.LockKeys([]string{"a", "b"}, nil)  // locks {"a", "b"}
defer unlock()

go func() {
    _, _ = l.LockKeys([]string{"b", "c"}, nil)  // can't lock {"b", "c"} 
}()                                             // since "b" has been locked already

time.Sleep(time.Millisecond * 10)
canceled, _ = l.LockKeys([]string{"d"}, nil)  // locks {"d"}

About

A Golang utility package which provides a way to lock a set of keys so that any subsequent call with a non-empty subset of already locked keys makes the goroutine waiting.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages