resource

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package resource describes require for object lifecycle management. Both Finalizer and Closer have similar concepts, they both exist so that different types can be used for resource cleanup with different method names as for some things like iterators, the verb close makes more sense than finalize and is more consistent with other types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancellableLifetime

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

CancellableLifetime describes a lifetime for a resource that allows checking out the resource and returning it and once cancelled will not allow any further checkouts.

func NewCancellableLifetime

func NewCancellableLifetime() *CancellableLifetime

NewCancellableLifetime returns a new cancellable resource lifetime.

func (*CancellableLifetime) Cancel

func (l *CancellableLifetime) Cancel()

Cancel will wait for all current checkouts to be returned and then will cancel the lifetime so that it cannot be checked out any longer.

func (*CancellableLifetime) ReleaseCheckout

func (l *CancellableLifetime) ReleaseCheckout()

ReleaseCheckout will decrement the number of current checkouts, it MUST only be called after a call to TryCheckout and must not be called more than once per call to TryCheckout or else it will panic as it will try to unlock an unlocked resource.

func (*CancellableLifetime) TryCheckout

func (l *CancellableLifetime) TryCheckout() bool

TryCheckout will try to checkout the resource, if the lifetime is already cancelled this will return false, otherwise it will return true and guarantee the lifetime is not cancelled until the checkout is returned. If this returns true you MUST call ReleaseCheckout later, otherwise the lifetime will never close and any caller calling Cancel will be blocked indefinitely.

type Closer added in v0.8.2

type Closer interface {
	Close()
}

Closer is an object that can be closed.

type CloserFn added in v0.8.2

type CloserFn func()

CloserFn is a function literal that is a closer.

func (CloserFn) Close added in v0.8.2

func (fn CloserFn) Close()

Close will call the function literal as a closer.

type Finalizer added in v0.8.2

type Finalizer interface {
	Finalize()
}

Finalizer finalizes a checked resource.

type FinalizerFn added in v0.8.2

type FinalizerFn func()

FinalizerFn is a function literal that is a finalizer.

func (FinalizerFn) Finalize added in v0.8.2

func (fn FinalizerFn) Finalize()

Finalize will call the function literal as a finalizer.

Jump to

Keyboard shortcuts

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