lock

package module
v0.0.0-...-f249337 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2021 License: BSD-3-Clause Imports: 1 Imported by: 8

README

Example

import "import.name/lock"
import "import.name/lock/unlock"

func ExampleLock() {
	var (
		mu    sync.Mutex
		count int
	)

	lock.Guard(&mu, func() {
		count++
	})

	// Go 1.18:

	n := lock.Guarded(&mu, func() int {
		return count
	})
	fmt.Println(n)
}

func ExampleUnlock() {
	var mu sync.Mutex

	mu.Lock()
	defer mu.Unlock()

	unlock.Guard(&mu, func() {
		time.Sleep(time.Second)
	})
}

Documentation

Overview

Package lock provides locking helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Guard

func Guard(lock sync.Locker, f func())

Guard invokes f while keeping the lock locked.

Types

This section is empty.

Directories

Path Synopsis
Package unlock provides unlocking helpers.
Package unlock provides unlocking helpers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL