Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("The loop is closed and no longer accepting tasks")
ErrClosed represents the error returned when we try to add or ready a task on a closed loop.
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, a channel of tasks that are ready to finalise on the VM, and a boolean that indicates if the loop is still accepting tasks. The channel holding the tasks pending finalising can be buffered or unbuffered.
Warning: id must be the first field in this struct as it's accessed atomically. Otherwise, on ARM and x86-32 it will panic. More information: https://golang.org/pkg/sync/atomic/#pkg-note-BUG.
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) AddAndExecute ¶
AddAndExecute combines Add and Ready for immediate execution.
func (*Loop) Eval ¶
Eval executes some code in the VM associated with the loop and returns an error if that execution fails.
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 ¶
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.