artifact

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 7 Imported by: 0

README

Artifact

A Model Controller pattern for async type updates

This projects looks at providing a miminal contract on using this pattern in future projects.

Examples

To show how would work, please take a look at the example.

Documentation

Overview

Package artifact defines a minimal library that can be used to define updatable types.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilValue is used when a nil paramater is provided
	ErrNilValue = errors.New("nil value provided")
)

Functions

This section is empty.

Types

type Artifact

type Artifact interface {
	// RWLocker is required to ensure go routine safety.
	RWLocker

	// ModifiedAt returns the time that the artifact
	// was last updated.
	ModifiedAt() time.Time

	// NotifyUpdate will inform all registered listeners
	// that a change has been made and will also update
	// modified time for the type.
	NotifyUpdated(ctx context.Context)

	// Register stores the information about the channel
	// and will send updates once Update is called successfully
	Register(notify chan<- struct{}) (err error)

	// Update must read the incoming reader to then
	// apply the update to the type, any issue will
	// return ar error and not notifications will happen.
	//
	// Note: Callee's a requried to call `Artifact.Lock` and `Artifact.Unlock`
	// respectively, they must not be called within the update method.
	Update(in io.Reader) error
}

Artifact allows other components to be notified when this type has changed

type Client

type Client interface {
	// Register will associate a name that can help with identifying
	// updates (ie. name = URI(/path/to/schema/definition)) that the client
	// is aware of and can pass those updates to the Artifact.
	// Register MUST fail when the initial load is not possible, any failures
	// after that point is treated as transitive and should be handled
	Register(ctx context.Context, name string, art Artifact) error

	// MonitorUpdates is used to update all registered components
	// that can be done as background task
	MonitorUpdates(ctx context.Context) error
}

Client represents a minimal viable interface that would be needed to provide async updates of Artifacts.

type Notifier

type Notifier struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Notifier is a partial implementation of Artifact so that it can be embedded into types to help reduce code duplication

func (*Notifier) ModifiedAt

func (n *Notifier) ModifiedAt() time.Time

func (*Notifier) NotifyUpdated

func (n *Notifier) NotifyUpdated(ctx context.Context)

func (*Notifier) Register

func (n *Notifier) Register(notify chan<- struct{}) error

type RWLocker

type RWLocker interface {
	sync.Locker

	RLock()
	RUnlock()
}

RWLocker is an extension of the sync.Locker to include the read lock methods.

Directories

Path Synopsis
examples
content command

Jump to

Keyboard shortcuts

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