An easy to use, key lock tool, lock according to the same key, not lock on different keys.
- 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.
- golang 1.10 +
- go get -u -v github.com/xiongxiong/cons
- 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.
var cons = GetCons()
c := cons.Wait("hello")
defer c.Done()
c := cons.Skip("hello")
defer c.Done()
if c.Skip {
println("skip")
return
}
c := cons.Queue("hello")
defer c.Done()
xiongxiong, ximengwuheng@163.com
The package cons is available under the MIT license. See the LICENSE file for more info.