Skip to content

me-cs/lazyLock

Repository files navigation

lazyLock

lazyLock go implementation

Go codecov Release Go Report Card Go Reference License: MIT

Description

lazyLock is great for business scenarios. When writing business-specific code, there may not be too many concurrent operations on a resource/scenario, so you don't want to hold a mutex for them, but you're worried about concurrent operations on it. Using lazyLock, it provides the ability to guarantee mutually exclusive operations when a conflict occurs, and to automatically release resources when the conflict disappears.

For example: most of the characteristics of the website access data in the "law of two or eight": 80% of the business access is concentrated in 20% of the data. We can use lazyLock to lock the data where the hot access occurs, without paying attention to the other 80% of the cold data.

English | 简体中文

Example use:

package main

import "github.com/me-cs/lazyLock"

func main() {

	unlock := lazyLock.Lock("key")

	//Your code that needs to be protected

	unlock()

}