RWSafe

package
v0.2.37 Latest Latest
Warning

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

Go to latest
Published: May 8, 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 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