loop

package
v0.0.0-...-dbc11f2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueBlocked = errors.New("queue currently blocked")

ErrQueueBlocked is returned when a new item should be added to the queue but it is currently blocked

Functions

This section is empty.

Types

type Loop

type Loop interface {
	// Start starts the loop
	Start(context.Context) error

	// Schedule a new task to be executed inside the loop
	Schedule(Task)

	// ScheduleAndWait schedules a task on the loop and waits for it to finish
	ScheduleAndWait(Task)

	// Stop the loop
	Stop()

	// Wait for the loop to finish
	Wait()
}

Loop is an async event loop for lua

func LGet

func LGet(state *lua.LState) Loop

LGet returns the current event loop from the given VM

func New

func New(opts *Options) (Loop, error)

New returns a new event loop

type Options

type Options struct {
	// InitVM is called with the new lua State before the event loop is initialized
	InitVM func(*lua.LState) error
}

Options used when creating a new event loop

type Queue

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

Queue implements a job queue for the event loop

func NewQueue

func NewQueue(loopName, name string) *Queue

NewQueue creates a new queue

func (*Queue) Block

func (q *Queue) Block()

Block the queue and deny any push action. Pop will still work

func (*Queue) Len

func (q *Queue) Len() int

Len returns the number of jobs queued

func (*Queue) Pop

func (q *Queue) Pop() Task

Pop returns the next task to execute from the queue or nil if the queue is empty

func (*Queue) PopWait

func (q *Queue) PopWait(ctx context.Context) (Task, error)

PopWait returns the next job from the queue and will block until either the context is cancelled or a job becomes available. If the queue is empty and blocked (i.e. Block() has been called), PopWait will return immediately with ErrQueueBlocked. If the provided context is canceled ctx.Err() will be returned

func (*Queue) Push

func (q *Queue) Push(item Task) error

Push pushes a new job onto the queue

func (*Queue) Unblock

func (q *Queue) Unblock()

Unblock unblocks the queue and allows new items to be added

type Task

type Task func(*lua.LState)

Task is a task that should be executed inside the loop

Jump to

Keyboard shortcuts

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