unlock

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: BSD-3-Clause Imports: 1 Imported by: 1

Documentation

Overview

Package unlock provides unlocking helpers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Guard

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

Guard unlocks the lock, invokes f, and locks the lock again.

Example
package main

import (
	"sync"
	"time"

	"import.name/lock/unlock"
)

func main() {
	var mu sync.Mutex

	mu.Lock()
	defer mu.Unlock()

	unlock.Guard(&mu, func() {
		time.Sleep(time.Microsecond)
	})
}
Output:

func Guarded

func Guarded[T any](lock sync.Locker, f func() T) T

Guarded unlocks the lock, invokes f, and locks the lock again. The return value is passed through.

Types

This section is empty.

Jump to

Keyboard shortcuts

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