RWSafe

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker added in v0.2.39

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

Locker is a struct that represents a locker.

func NewLocker added in v0.2.39

func NewLocker(cond bool) *Locker

NewLocker creates a new Locker with the given condition.

Parameters:

  • cond: The condition of the locker.

Returns:

  • *Locker: A pointer to the new Locker.

func (*Locker) ModifyCond added in v0.2.39

func (l *Locker) ModifyCond(cond bool)

ModifyCond modifies the condition of the locker.

Parameters:

  • cond: The new condition of the locker.

func (*Locker) WaitForCond added in v0.2.39

func (l *Locker) WaitForCond(do func(cond bool))

WaitForCond waits for the condition of the locker to be true.

Parameters:

  • do: The function to execute when the condition is true.

type RWSafe

type RWSafe[T any] struct {
	// contains filtered or unexported fields
}

RWSafe is a thread-safe, generic data structure that allows multiple goroutines to read and write to a value in a synchronized manner.

func NewRWSafe

func NewRWSafe[T any](value T) *RWSafe[T]

NewRWSafe is a function that creates and returns a new instance of a RWSafe.

Parameters:

  • value: The initial value to be stored in the RWSafe.

Returns:

  • *RWSafe[T]: A pointer to the newly created RWSafe.

func (*RWSafe[T]) DoRead

func (rw *RWSafe[T]) DoRead(f func(T))

DoRead is a method of the RWSafe type. It is used to perform a read operation on the value stored in the RWSafe. Through the function parameter, the caller can access the value in a read-only manner.

Parameters:

  • f: A function that takes a value of type T as a parameter and returns nothing.

func (*RWSafe[T]) DoWrite

func (rw *RWSafe[T]) DoWrite(f func(T))

DoWrite is a method of the RWSafe type. It is used to perform a write operation on the value stored in the RWSafe. Through the function parameter, the caller can access the value in a read-write manner.

Parameters:

  • f: A function that takes a pointer to a value of type T as a parameter and returns nothing.

func (*RWSafe[T]) Get

func (rw *RWSafe[T]) Get() T

Get is a method of the RWSafe type. It is used to retrieve the value stored in the RWSafe.

Returns:

  • T: The value stored in the RWSafe.

func (*RWSafe[T]) Set

func (rw *RWSafe[T]) Set(value T)

Set is a method of the RWSafe type. It is used to set the value stored in the RWSafe.

Parameters:

  • value: The new value to be stored in the RWSafe.

Jump to

Keyboard shortcuts

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