loop

package
v0.0.0-...-5871ae9 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2017 License: BSD-3-Clause Imports: 4 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loop

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

Loop encapsulates the event loop's state. This includes the vm on which the loop operates, a monotonically incrementing event id, a map of tasks that aren't ready yet, keyed by their ID, and a channel of tasks that are ready to finalise on the VM. The channel holding the tasks pending finalising can be buffered or unbuffered.

func New

func New(vm *otto.Otto) *Loop

New creates a new Loop with an unbuffered ready queue on a specific VM.

func NewWithBacklog

func NewWithBacklog(vm *otto.Otto, backlog int) *Loop

NewWithBacklog creates a new Loop on a specific VM, giving it a buffered queue, the capacity of which being specified by the backlog argument.

func (*Loop) Add

func (l *Loop) Add(t Task)

Add puts a task into the loop. This signals to the loop that this task is doing something outside of the JavaScript environment, and that at some point, it will become ready for finalising.

func (*Loop) Eval

func (l *Loop) Eval(s interface{}) error

Eval executes some code in the VM associated with the loop and returns an error if that execution fails.

func (*Loop) EvalAndRun

func (l *Loop) EvalAndRun(s interface{}) error

EvalAndRun is a combination of Eval and Run. Creatively named.

func (*Loop) Ready

func (l *Loop) Ready(t Task)

Ready signals to the loop that a task is ready to be finalised. This might block if the "ready channel" in the loop is at capacity.

func (*Loop) Remove

func (l *Loop) Remove(t Task)

Remove takes a task out of the loop. This should not be called if a task has already become ready for finalising. Warranty void if constraint is broken.

func (*Loop) Run

func (l *Loop) Run() error

Run handles the task scheduling and finalisation. It will block until there's no work left to do, or an error occurs.

func (*Loop) VM

func (l *Loop) VM() *otto.Otto

VM gets the JavaScript interpreter associated with the loop. This will be some kind of Otto object, but it's wrapped in an interface so the `ottoext` library can work with forks/extensions of otto.

type Task

type Task interface {
	SetID(id int64)
	GetID() int64
	Execute(vm *otto.Otto, l *Loop) error
	Cancel()
}

Task represents something that the event loop can schedule and run.

Task describes two operations that will almost always be boilerplate, SetID and GetID. They exist so that the event loop can identify tasks after they're added.

Execute is called when a task has been pulled from the "ready" queue.

Cancel is called when a task is removed from the loop without being finalised.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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