💾 Archived View for godocs.io › github.com › mediocregopher › radix › v4 › internal › proc captured on 2023-11-04 at 11:43:42. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-09-28)

➡️ Next capture (2023-12-28)

🚧 View Differences

-=-=-=-=-=-=-

package proc - github.com/mediocregopher/radix/v4/internal/proc - godocs.io

import "github.com/mediocregopher/radix/v4/internal/proc"

Package proc implements a simple framework for initializing and cleanly shutting down components.

Variables

var ErrClosed = errors.New("closed")

ErrClosed indicates that an operation could not be completed because the component has been closed.

Types

type Proc

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

Proc implements a lightweight pattern for setting up and tearing down components cleanly and consistently.

func New

func New() *Proc

New initializes and returns a clean Proc.

func (*Proc) Close

func (p *Proc) Close(fn func() error) error

Close marks this Proc as having been closed (all methods will return ErrClosed after this), waits for all go-routines spawned with Run to return, and then calls the given callback. If Close is called multiple times it will return ErrClosed the subsequent times without taking any other action.

func (*Proc) ClosedCh

func (p *Proc) ClosedCh() <-chan struct{}

ClosedCh returns a channel which will be closed when the Proc is closed.

func (*Proc) IsClosed

func (p *Proc) IsClosed() bool

IsClosed returns true if Close has been called.

func (*Proc) PrefixedClose

func (p *Proc) PrefixedClose(prefixFn, fn func() error) error

PrefixedClose is like Close but it will additionally perform a callback prior to marking the Proc as closed.

func (*Proc) Run

func (p *Proc) Run(fn func(ctx context.Context))

Run spawns a new go-routine which will run with the given callback. The callback's context will be closed when Close is called on Proc, and the go-routine must return for Close to return.

func (*Proc) WithLock

func (p *Proc) WithLock(fn func() error) error

WithLock performs the given callback while holding a write lock on an internal RWMutex. This will return ErrClosed without calling the callback if Close has already been called.

func (*Proc) WithRLock

func (p *Proc) WithRLock(fn func() error) error

WithRLock performs the given callback while holding a read lock on an internal RWMutex. This will return ErrClosed without calling the callback if Close has already been called.

Details

Version: v4.1.4 (latest)

Platform: linux/amd64

Imports: 3 packages

Refresh now

Back to home

Search