util

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallWithTimeout

func CallWithTimeout(ctx context.Context, fn func() error, timeoutCallback func()) error

CallWithTimeout invokes the given function and waits until either it finishes or the given context finishes. If the context finishes before the function finishes, the timeoutCallback function is invoked.

func TestDirectory

func TestDirectory(t *testing.T) string

TestDirectory returns a temporary directory for this test only. Calling TestDirectory multiple times for the same instance of t returns a new directory every time.

func WaitFor

func WaitFor(t *testing.T, p Predicate, timeout time.Duration, message string, msgArgs ...interface{}) bool

func WrapError

func WrapError(err error, cause error) error

WrapError returns an error that wraps a cause. In contrary to fmt.Errorf, errors.Is can be used on both the outer error and cause.

Types

type ContextRWLocker

type ContextRWLocker struct {
	// contains filtered or unexported fields
}

ContextRWLocker returns a RWMutex that supports context cancellation.

func (*ContextRWLocker) Lock

func (c *ContextRWLocker) Lock()

Lock simply calls the underlying lock.

func (*ContextRWLocker) LockContext

func (c *ContextRWLocker) LockContext(ctx context.Context) error

LockContext locks the RWLocker with the given context. If the context is canceled the function will return immediately with the error from the context. It will still acquire the lock on the background, but it will be released immediately.

func (*ContextRWLocker) RLock

func (c *ContextRWLocker) RLock()

RLock simply calls the underlying lock.

func (*ContextRWLocker) RLockContext

func (c *ContextRWLocker) RLockContext(ctx context.Context) error

RLockContext locks the RWLocker with the given context. If the context is canceled the function will return immediately with the error from the context. It will still acquire the lock on the background, but it will be released immediately.

func (*ContextRWLocker) RLocker

func (c *ContextRWLocker) RLocker() sync.Locker

RLocker simply calls the underlying lock.

func (*ContextRWLocker) RUnlock

func (c *ContextRWLocker) RUnlock()

RUnlock simply calls the underlying lock.

func (*ContextRWLocker) TryLock

func (c *ContextRWLocker) TryLock() bool

TryLock simply calls the underlying lock.

func (*ContextRWLocker) TryRLock

func (c *ContextRWLocker) TryRLock() bool

TryRLock simply calls the underlying lock.

func (*ContextRWLocker) Unlock

func (c *ContextRWLocker) Unlock()

Unlock simply calls the underlying lock.

type Predicate

type Predicate func() (bool, error)

type RWLocker

type RWLocker interface {
	sync.Locker
	RLock()
	TryRLock() bool
	RUnlock()
	TryLock() bool
	RLocker() sync.Locker
}

RWLocker defines the interface for a read-write lock like sync.RWMutex

Jump to

Keyboard shortcuts

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