Skip to content

An easy to use, key lock tool, lock according to the same key, not lock on different keys.

License

Notifications You must be signed in to change notification settings

xiongxiong/cons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An easy to use, key lock tool, lock according to the same key, not lock on different keys.

Contents

Features

  • wait on key using, for concurrent usages, only the first usage will execute, others will wait for the first to finish, and then all can continue at the same time, used for waiting for something to happen once and only once, and it's a forerunner condition.
  • skip on key using, for concurrent usages, only the first usage will execute, others will be marked as skip, used for something to happen once at the same time.
  • queue on key using, for concurrent usages, usages will be queued one by one, until all finished.

Requirements

  • golang 1.10 +

Installation

  • go get -u -v github.com/xiongxiong/cons

Usage

  • If you have only a collection of conditions, you can use the default cons. If you have several collections of conditions which may have same key, you should create different cons for collections to avoid collisions.

Example

Get cons (lock map)

var cons = GetCons()

Wait on key using

c := cons.Wait("hello")
defer c.Done()

Skip on key using

c := cons.Skip("hello")
defer c.Done()

if c.Skip {
    println("skip")
    return
}

Queue on key using

c := cons.Queue("hello")
defer c.Done()

Author

xiongxiong, ximengwuheng@163.com

License

The package cons is available under the MIT license. See the LICENSE file for more info.

About

An easy to use, key lock tool, lock according to the same key, not lock on different keys.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages