eventloop

package
v0.0.0-...-29b559b Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 6 Imported by: 44

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) 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)) bool

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. Returns true on success or false if the loop is terminated (see Terminate()).

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. If the loop is terminated (see Terminate()) returns nil.

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. If the loop is terminated (see Terminate()) returns nil.

func (*EventLoop) Start

func (loop *EventLoop) Start()

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) StartInForeground

func (loop *EventLoop) StartInForeground()

StartInForeground starts the event loop in the current goroutine. The loop continues to run until Stop() is called. If the loop is already started it will panic. Use this instead of Start if you want to recover from panics that may occur while calling native Go functions from within setInterval and setTimeout callbacks.

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 (use Terminate() instead if you want this). It is not allowed to run Start() (or Run()) and Stop() or Terminate() 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) Terminate

func (loop *EventLoop) Terminate()

Terminate stops the loop and clears all active timeouts and intervals. After it returns there are no active timers or goroutines associated with the loop. Any attempt to submit a task (by using RunOnLoop(), SetTimeout() or SetInterval()) will not succeed. After being terminated the loop can be restarted again by using Start() or Run(). This method must not be called concurrently with Stop*(), Start(), or Run().

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 EnableConsole

func EnableConsole(enableConsole bool) Option

EnableConsole controls whether the "console" module is loaded into the runtime used by the loop. By default, loops are created with the "console" module loaded, pass EnableConsole(false) to NewEventLoop to disable this behavior.

func WithRegistry

func WithRegistry(registry *require.Registry) 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