Documentation ¶
Index ¶
- type Collection
- func (tc *Collection) Get(ctx context.Context, hash string) (template *Template, found bool)
- func (tc *Collection) Pop(ctx context.Context, hash string) (template *Template, found bool)
- func (tc *Collection) Push(ctx context.Context, hash string, config TemplateConfig) (added bool, unlock Unlock)
- func (tc *Collection) RemoveAll(ctx context.Context)
- func (tc *Collection) RemoveUnsafe(_ context.Context, hash string)
- type LockedTemplate
- type Template
- func (t *Template) GetConfig(_ context.Context) TemplateConfig
- func (t *Template) GetState(_ context.Context) TemplateState
- func (t *Template) GetStateWithLock(_ context.Context) (TemplateState, LockedTemplate)
- func (t *Template) SetState(ctx context.Context, newState TemplateState)
- func (t *Template) WaitUntilFinalized(ctx context.Context, timeout time.Duration) (exitState TemplateState)
- type TemplateConfig
- type TemplateState
- type Unlock
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) 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) 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 )