tsslice

package
v1.70.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package tsslice provides a collection of thread-safe slice functions that can be safely used between multiple goroutines.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append[T any](mux threadsafe.Locker, slice *[]T, item ...T)

Append is a thread-safe version of the Go built-in append function.

Example (Concurrent)
Output:

[0 1 2 3 4]
Example (Multiple)
Output:

[Hello World]
Example (Simple)
Output:

[Hello World]
Example (Slice)
Output:

[Hello World]

func Get

func Get[T any](mux threadsafe.RLocker, slice []T, key int) T

Get is a thread-safe function to get a value by key in a slice.

Example
Output:

Hello
World

func Len

func Len[T any](mux threadsafe.RLocker, slice []T) int

Len is a thread-safe function to get the length of a slice.

Example
Output:

2

func Set

func Set[T any](mux threadsafe.Locker, slice []T, key int, value T)

Set is a thread-safe function to assign a value to a key in a slice.

Example
Output:

[Hello World]

Types

This section is empty.

Jump to

Keyboard shortcuts

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