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 NewWithBacklog ¶
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 ¶
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 ¶
Eval executes some code in the VM associated with the loop and returns an error if that execution fails.
func (*Loop) EvalAndRun ¶
EvalAndRun is a combination of Eval and Run. Creatively named.
func (*Loop) Ready ¶
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 ¶
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.
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.