Documentation ¶
Overview ¶
Package async Loader adapted from Egon's https://github.com/egonelbre/expgio. Package async Loader adapted from Egon's https://github.com/egonelbre/expgio.
Index ¶
Constants ¶
const DefaultMaxLoaded = 10
DefaultMaxLoaded is used when no max is specified.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynamicWorkerPool ¶
type DynamicWorkerPool struct { // Workers specifies the maximum allowed number of concurrent workers in // this pool. Defaults to NumCPU. Workers int64 // once time initialization. sync.Once // contains filtered or unexported fields }
DynamicWorkerPool implements a simple dynamic-sized worker pool that spins up a new worker per unit of work, until the maximum number of workers has been reached.
This pool will minimize idle memory as goroutines will die off once complete, but will incur the latency cost, such that it is, of spinning up goroutines on-the-fly.
Additionally, ordering of work is inconsistent with highly dynamic layouts.
func (*DynamicWorkerPool) Schedule ¶
func (p *DynamicWorkerPool) Schedule(work func())
Schedule work to be executed by the available workers. This is a blocking call if all workers are busy.
Workers are limited by a buffer of semaphores. Each worker holds a semaphore for the duration of its life and returns it before exiting.
type FixedWorkerPool ¶
type FixedWorkerPool struct { // Workers specifies the number of concurrent workers in this pool. Workers int // once time initialization. sync.Once // contains filtered or unexported fields }
FixedWorkerPool implements a simple fixed-size worker pool that lets go runtime schedule work atop some number of goroutines.
This pool will minimize goroutine latency at the cost of maintaining the configured number of goroutines throughout the lifetime of the pool.
func (*FixedWorkerPool) Schedule ¶
func (p *FixedWorkerPool) Schedule(work func())
Schedule work to be executed by the available workers. This is a blocking call if all workers are busy.
type Loader ¶
type Loader struct { // Scheduler provides scheduling behaviour. Defaults to a sized worker pool. // The caller can provide a scheduler that implements the best strategy for // the use case. Scheduler Scheduler // MaxLoaded specifies the maximum number of resources to load before // de-allocating old resources. MaxLoaded int // contains filtered or unexported fields }
Loader is an asynchronously loaded resource. Start and poll a resource with Schedule method. Track frames with Frame method to detect stale data. Respond to updates in event loop by selecting on Updated channel.
func (*Loader) Frame ¶
Frame wraps a widget and tracks frame updates.
Typically, you should wrap your entire UI so that each frame is counted. However, it is sufficient to wrap only the widget that expects to use the loader during its layout.
A frame is currently updating if activeFrame < finishedFrame.
func (*Loader) Schedule ¶
Schedule a resource to be loaded asynchronously, returning a resource that will hold the loaded value at some point.
Schedule should be called per frame and the state of the resource checked accordingly.
The first call will queue up the load, subsequent calls will poll for the status.
func (*Loader) Shutdown ¶
func (l *Loader) Shutdown()
Shutdown ends the background processing of the loader, if any is happening.
func (*Loader) Stats ¶
func (l *Loader) Stats() LoaderStats
Stats reports runtime data about this loader.
type LoaderStats ¶
LoaderStats tracks some stats about the loader.
type Resource ¶
type Resource struct { // State reports current state for this resource. State State // Value for the resource. Nil if not ready. Value interface{} }
Resource is an async entity that can be in various states and potentially contain a value.
type Scheduler ¶
type Scheduler interface {
// Schedule a piece of work. This method is allowed to block.
Schedule(func())
}
Scheduler schedules work according to some strategy. Implementations can implement the best way to distribute work for a given application.
TODO(jfm): context cancellation.