Documentation
¶
Index ¶
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)
- func (m *Map[K, V]) CompareAndSwap(key K, old, new V) (swapped bool)
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Load(key K) (value V, ok bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *Map[K, V]) Range(yield func(key K, value V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) Swap(key K, value V) (previous V, loaded bool)
- type Mutex
- type Pool
- type RWMutex
- type SlicePool
- type WaitGroup
- type WorkPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a type-safe generic wrapper around sync.m.
func (*Map[K, V]) Clear ¶
func (m *Map[K, V]) Clear()
Clear deletes all the entries, resulting in an empty Map.
func (*Map[K, V]) CompareAndDelete ¶
CompareAndDelete deletes the entry for key if its value is equal to old. The value type parameter must be of a comparable type.
If there is no current value for key in the map, CompareAndDelete returns false.
func (*Map[K, V]) CompareAndSwap ¶
CompareAndSwap swaps the old and new values for key if the value stored in the map is equal to old. The value type parameter must be of a comparable type.
func (*Map[K, V]) Load ¶
Load returns the value stored in the map for a key, or the zero value if no value is present. The ok result indicates whether value was found in the map.
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete deletes the value for a key, returning the previous value if any. If there is no previous value, it returns the zero value. The loaded result reports whether the key was present.
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
Pool is a set of temporary items that may be individually saved and retrieved. It is intended to mirror sync.Pool, except it has been specifically designed to meet the needs of pkg/sftp.
Any item stored in the Pool will be held onto indefinitely, and items are returned for reuse in a round-robin order.
A Pool is safe for use by multiple goroutines simultaneously.
Pool's purpose is to cache allocated but unused items for later reuse, relieving pressure on the garbage collector and amortizing allocation overhead.
Unlike the standard library Pool, it is suitable to act as a free list of short-lived items, since the free list is maintained as a channel, and thus has fairly low overhead.
func NewPool ¶
NewPool returns a Pool set to hold onto depth number of pointers to the given type.
It will panic if given a negative depth, the same as making a negative-buffer channel.
func (*Pool[T]) Get ¶
func (p *Pool[T]) Get() *T
Get retrieves an item from the pool, and then returns it to the caller. If the pool is empty, it will return a pointer to a newly allocated item.
A nil Pool is treated as an empty pool, that is, it always returns a pointer to a newly allocated item.
type SlicePool ¶
type SlicePool[S []T, T any] struct { // contains filtered or unexported fields }
SlicePool is a set of temporary slices that may be individually saved and retrieved. It is intended to mirror sync.Pool, except it has been specifically designed to meet the needs of pkg/sftp.
Any slice stored in the SlicePool will be held onto indefinitely, and slices are returned for reuse in a round-robin order.
A SlicePool is safe for use by multiple goroutines simultaneously.
SlicePool's purpose is to cache allocated but unused slices for later reuse, relieving pressure on the garbage collector and amortizing allocation overhead.
Unlike the standard library Pool, it is suitable to act as a free list of short-lived slices, since the free list is maintained as a channel, and thus has fairly low overhead.
func NewSlicePool ¶
NewSlicePool returns a SlicePool set to hold onto depth number of items, and discard any slice with a capacity greater than the cull length.
It will panic if given a negative depth, the same as making a negative-buffer channel. It will also panic if given a zero or negative cull length.
func (*SlicePool[S, T]) Get ¶
func (p *SlicePool[S, T]) Get() S
Get retrieves a slice from the pool, sets the length to the capacity, and then returns it to the caller. If the pool is empty, it will return a nil slice.
A nil SlicePool is treated as an empty pool, that is, it returns only nil slices.
type WorkPool ¶
type WorkPool[T any] struct { // contains filtered or unexported fields }
WorkPool is a set of temporary work channels that can co-ordinate returns of work done among goroutines. It is intended to mimic sync.Pool, except it has been specifically designed to meet the needs of pkg/sftp.
A WorkPool will be filled to capacity at creation with work channels of the given type and a buffer of 1. It will track channels that have been handed out through Get, blocking on Close until all of them have been returned.
WorkPool's purpose is also to block allocate work channels for reuse during concurrent transfers, relieving pressure on the garbage collector and amortizing allocation overhead. While also co-ordinating outstanding work, so the caller can wait for all work to be complete.
func NewWorkPool ¶
NewWorkPool returns a WorkPool set to hold onto depth number of channels of the given type.
It will panic if given a negative depth, the same as making a negative-buffer channel.
func (*WorkPool[T]) Close ¶
Close closes the WorkPool to all further Get request. Close then waits for all outstanding channels to be returned to the pool.
After calling Close, all calls to Get will return a nil work channel and false.
After Close returns, the pool will be empty, and all work channels will have been discarded and ready for the garbage collector.
It is an error not a panic to close a nil WorkPool. However, Close will panic if called more than once.
func (*WorkPool[T]) Get ¶
Get retrieves a work channel from the pool, and then returns it to the caller, or it returns a nil channel, and false if the WorkPool has been closed.
If no work channels are available, it will block until a work channel has been returned to the pool.
A nil WorkPool will simply always return a new work channel and true.