Documentation ¶
Index ¶
- type EventLoop
- func (loop *EventLoop) ClearInterval(i *Interval)
- func (loop *EventLoop) ClearTimeout(t *Timer)
- func (loop *EventLoop) Run(fn func(*goja.Runtime))
- func (loop *EventLoop) RunOnLoop(fn func(*goja.Runtime)) bool
- func (loop *EventLoop) SetInterval(fn func(*goja.Runtime), timeout time.Duration) *Interval
- func (loop *EventLoop) SetTimeout(fn func(*goja.Runtime), timeout time.Duration) *Timer
- func (loop *EventLoop) Start()
- func (loop *EventLoop) StartInForeground()
- func (loop *EventLoop) Stop() int
- func (loop *EventLoop) StopNoWait()
- func (loop *EventLoop) Terminate()
- type Immediate
- type Interval
- type Option
- type Timer
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 (*EventLoop) ClearInterval ¶
ClearInterval cancels an Interval returned by SetInterval. ClearInterval is safe to call inside or outside the loop.
func (*EventLoop) ClearTimeout ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 Option ¶
type Option func(*EventLoop)
func EnableConsole ¶
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.