filepool

package
v1.76.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package filepool keeps a set of reusable write handles open on a single remote path, one per connection, so several goroutines can write to the same file at once without sharing a handle.

It is used by backends that implement fs.OpenWriterAter over a connection pool, where the core writes the chunks of a large file concurrently at non-overlapping offsets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool hands out handles of type T for a single file. Handles are reused when free and opened on demand otherwise. It is safe for concurrent use.

The zero value is not usable; call New.

func New

func New[T any](ctx context.Context, open func(context.Context) (T, error), release func(handle T, err error) error) *Pool[T]

New returns a Pool.

open opens a fresh handle on its own connection. release closes a handle and returns its connection: err is the error that made the handle unusable (nil when the handle is simply being drained) and the returned error is the result of closing it.

func (*Pool[T]) Drain

func (p *Pool[T]) Drain() error

Drain releases every free handle, closing them concurrently, and returns the first error encountered.

func (*Pool[T]) Get

func (p *Pool[T]) Get() (T, error)

Get returns a free handle, opening a new one if none are free.

func (*Pool[T]) Put

func (p *Pool[T]) Put(handle T, err error)

Put returns a handle to the pool. If err is non-nil the write that used the handle failed, so the handle is released instead of being reused.

Jump to

Keyboard shortcuts

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