templates

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

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

func NewCollection

func NewCollection() *Collection

func (*Collection) Get

func (tc *Collection) Get(ctx context.Context, hash string) (template *Template, found bool)

Get gets the requested template without removing it from the collection.

func (*Collection) Pop

func (tc *Collection) Pop(ctx context.Context, hash string) (template *Template, found bool)

Pop removes a template from the collection returning it to the caller.

func (*Collection) Push

func (tc *Collection) Push(ctx context.Context, hash string, config TemplateConfig) (added bool, unlock Unlock)

Push tries to add a new template to the collection. If the template already exists and the config matches, added=false is returned. If config doesn't match, the template is overwritten and added=true is returned. This function locks the collection and no matter what is its output, the unlock function needs to be called to release the lock.

func (*Collection) RemoveAll

func (tc *Collection) RemoveAll(ctx context.Context)

RemoveAll removes all templates from the collection.

func (*Collection) RemoveUnsafe

func (tc *Collection) RemoveUnsafe(_ context.Context, hash string)

RemoveUnsafe removes the template and can be called ONLY IF THE COLLECTION IS LOCKED.

type LockedTemplate

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

func (LockedTemplate) SetState

func (l LockedTemplate) SetState(_ context.Context, newState TemplateState)

SetState sets a new state of the locked template (without acquiring the lock again).

func (*LockedTemplate) Unlock

func (l *LockedTemplate) Unlock()

Unlock releases the locked template.

type Template

type Template struct {
	TemplateConfig
	db.Database
	// contains filtered or unexported fields
}

func NewTemplate

func NewTemplate(hash string, config TemplateConfig) *Template

func (*Template) GetConfig

func (t *Template) GetConfig(_ context.Context) TemplateConfig

func (*Template) GetState

func (t *Template) GetState(_ context.Context) TemplateState

GetState locks the template and checks its state.

func (*Template) GetStateWithLock

func (t *Template) GetStateWithLock(_ context.Context) (TemplateState, LockedTemplate)

GetStateWithLock gets the current state leaving the template locked. REMEMBER to unlock it when you no longer need it locked.

func (*Template) SetState

func (t *Template) SetState(ctx context.Context, newState TemplateState)

SetState sets the desired state and broadcasts the change to whoever is waiting for it.

func (*Template) WaitUntilFinalized

func (t *Template) WaitUntilFinalized(ctx context.Context, timeout time.Duration) (exitState TemplateState)

WaitUntilFinalized checks the current template state and returns directly if it's 'Finalized'. If it's not, the function waits the given timeout until the template state changes. On timeout, the old state is returned, otherwise - the new state.

type TemplateConfig

type TemplateConfig struct {
	db.DatabaseConfig
}

func (TemplateConfig) Equals

func (c TemplateConfig) Equals(other TemplateConfig) bool

type TemplateState

type TemplateState int32
const (
	TemplateStateInit TemplateState = iota
	TemplateStateDiscarded
	TemplateStateFinalized
)

type Unlock

type Unlock func()

Unlock function used to release the collection lock.

Jump to

Keyboard shortcuts

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