loader

package
v0.34.0 Latest Latest
Warning

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

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

Documentation

Overview

Package loader provides primitives to load an applet both when the underlying file changes and on demand when an update is requested.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

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

Loader is a structure to provide applet loading when a file changes or on demand.

func NewLoader

func NewLoader(
	fs fs.FS,
	watch bool,
	fileChanges chan bool,
	updatesChan chan Update,
	maxDuration int,
	timeout int,
	renderGif bool,
) (*Loader, error)

NewLoader instantiates a new loader structure. The loader will read off of fileChanges channel and write updates to the updatesChan. Updates are base64 encoded WebP strings. If watch is enabled, both file changes and on demand requests will send updates over the updatesChan.

func (*Loader) CallSchemaHandler added in v0.16.0

func (l *Loader) CallSchemaHandler(ctx context.Context, handlerName, parameter string) (string, error)

func (*Loader) GetSchema added in v0.16.0

func (l *Loader) GetSchema() []byte

func (*Loader) LoadApplet

func (l *Loader) LoadApplet(config map[string]string) (string, error)

LoadApplet loads the applet on demand.

TODO: This method is thread safe, but has a pretty glaring race condition. If two callers request an update at the same time, they have the potential to get each others update. At the time of writing, this method is only called when you refresh a webpage during app development - so it doesn't seem likely that it's going to cause issues in the short term.

func (*Loader) Run

func (l *Loader) Run() error

Run executes the main loop. If there are config changes, those are recorded. If there is an on-demand request, it's processed and sent back to the caller and sent out as an update. If there is a file change, we update the applet and send out the update over the updatesChan.

type Update added in v0.15.0

type Update struct {
	Image     string
	ImageType string
	Schema    string
	Err       error
}

Jump to

Keyboard shortcuts

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