Documentation
¶
Overview ¶
Package loader implements the ability to define a graph of tasks and dependencies that produce results, and solve the graph incrementally or totally, including concurrently.
For example, this could be used to implement a loading screen for a computer game with a progress bar that updates in real time, with images being decoded concurrently with files being loaded from disk, and synchronised with the main thread for safe OpenGL operations such as creating texture objects on the GPU.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Inputs ¶
func (*Inputs) AssertNoErrors ¶
func (n *Inputs) AssertNoErrors()
AssertNoErrors panics unless all the inputs (if any) have nil error values.
func (*Inputs) AssertNone ¶
func (n *Inputs) AssertNone()
AssertNone panics unless the inputs are empty
func (*Inputs) AssertNoneDirect ¶
func (n *Inputs) AssertNoneDirect()
AssertNoneDirect panics unless the direct inputs are empty
func (*Inputs) AssertNoneNamed ¶
func (n *Inputs) AssertNoneNamed()
AssertNoneNamed panics unless the named inputs are empty
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is a dependency graph (represented as a DAG) modelling tasks that perform a unit of work, either alone or on the results of some previous tasks that must complete first.
func (*Loader) Add ¶
Add creates a new vertex in a loader dependency graph. Inputs are provided as arguments to the [Task.Load] method.
func (*Loader) Step ¶
Step performs (or continues to perform) each task in the dependency graph, where possible using concurrency. It does not block, and must be repeatedly called until done, when it returns false. If busy-waiting, it is a good idea to have some sort of small delay between each iteration.
func (*Loader) Walk ¶
func (l *Loader) Walk()
Walk performs each task in the dependency graph, where possible using concurrency. It blocks until complete.
func (*Loader) WalkSynchronous ¶
WalkSynchronous performs each task in the dependency graph, in topological sorted order, one-by-one in sequence until complete. The visit function is a callback, called for each task, where i is the progress out of the total number of tasks.
type Manager ¶
type Manager interface { Queue(WorkerTask) Start(chan WorkerResult) Stop() }
type ManagerAsync ¶
type ManagerAsync struct { MaxWorkers int // contains filtered or unexported fields }
func (*ManagerAsync) Queue ¶
func (m *ManagerAsync) Queue(t WorkerTask)
func (*ManagerAsync) Start ¶
func (m *ManagerAsync) Start(resultChan chan<- WorkerResult, bufSize int)
func (*ManagerAsync) Stop ¶
func (m *ManagerAsync) Stop()
type ManagerSync ¶
type ManagerSync struct {
// contains filtered or unexported fields
}
func (*ManagerSync) Queue ¶
func (m *ManagerSync) Queue(t WorkerTask)
func (*ManagerSync) Start ¶
func (m *ManagerSync) Start(resultChan chan<- WorkerResult, bufSize int)
func (*ManagerSync) Stop ¶
func (m *ManagerSync) Stop()
type Vertex ¶
type Vertex struct {
// contains filtered or unexported fields
}
Vertex represents a task in the loader dependency graph.