eventloop

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventLoop

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

func NewEventLoop

func NewEventLoop(opts ...Option) *EventLoop

func (*EventLoop) ClearInterval

func (loop *EventLoop) ClearInterval(i *Interval)

ClearInterval cancels an Interval returned by SetInterval. ClearInterval is safe to call inside or outside the loop.

func (*EventLoop) ClearTimeout

func (loop *EventLoop) ClearTimeout(t *Timer)

ClearTimeout cancels a Timer returned by SetTimeout if it has not run yet. ClearTimeout is safe to call inside or outside the loop.

func (*EventLoop) Registry

func (loop *EventLoop) Registry() *require.Registry

func (*EventLoop) Run

func (loop *EventLoop) Run(fn func(*goja.Runtime))

Run calls the specified function, starts the event loop and waits until there are no more delayed jobs to run after which it stops the loop and returns. The instance of goja.Runtime that is passed to the function and any Values derived from it must not be used outside the function. Do NOT use this function while the loop is already running. Use RunOnLoop() instead. If the loop is already started it will panic.

func (*EventLoop) RunOnLoop

func (loop *EventLoop) RunOnLoop(fn func(*goja.Runtime))

RunOnLoop schedules to run the specified function in the context of the loop as soon as possible. The order of the runs is preserved (i.e. the functions will be called in the same order as calls to RunOnLoop()) The instance of goja.Runtime that is passed to the function and any Values derived from it must not be used outside the function. It is safe to call inside or outside the loop.

func (*EventLoop) Runtime

func (loop *EventLoop) Runtime() *goja.Runtime

Runtime returns the goja.Runtime instance associated with the loop.

func (*EventLoop) SetInterval

func (loop *EventLoop) SetInterval(fn func(*goja.Runtime), timeout time.Duration) *Interval

SetInterval schedules to repeatedly run the specified function in the context of the loop as soon as possible after every specified timeout period. SetInterval returns an Interval which can be passed to ClearInterval. The instance of goja.Runtime that is passed to the function and any Values derived from it must not be used outside the function. SetInterval is safe to call inside or outside the loop.

func (*EventLoop) SetTimeout

func (loop *EventLoop) SetTimeout(fn func(*goja.Runtime), timeout time.Duration) *Timer

SetTimeout schedules to run the specified function in the context of the loop as soon as possible after the specified timeout period. SetTimeout returns a Timer which can be passed to ClearTimeout. The instance of goja.Runtime that is passed to the function and any Values derived from it must not be used outside the function. SetTimeout is safe to call inside or outside the loop.

func (*EventLoop) Start

func (loop *EventLoop) Start() *goja.Runtime

Start the event loop in the background. The loop continues to run until Stop() is called. If the loop is already started it will panic.

func (*EventLoop) Stop

func (loop *EventLoop) Stop() int

Stop the loop that was started with Start(). After this function returns there will be no more jobs executed by the loop. It is possible to call Start() or Run() again after this to resume the execution. Note, it does not cancel active timeouts. It is not allowed to run Start() (or Run()) and Stop() concurrently. Calling Stop() on a non-running loop has no effect. It is not allowed to call Stop() from the loop, because it is synchronous and cannot complete until the loop is not running any jobs. Use StopNoWait() instead. return number of jobs remaining

func (*EventLoop) StopNoWait

func (loop *EventLoop) StopNoWait()

StopNoWait tells the loop to stop and returns immediately. Can be used inside the loop. Calling it on a non-running loop has no effect.

func (*EventLoop) Wait

func (loop *EventLoop) Wait()

type Immediate

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

type Interval

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

type Option

type Option func(*EventLoop)

func WithRegistry

func WithRegistry(registry *require.Registry) Option

func WithRuntime

func WithRuntime(vm *goja.Runtime) Option

type Timer

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

Jump to

Keyboard shortcuts

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