eventloop

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 4 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
}

EventLoop manages Go-backed timers for setTimeout/setInterval and pending fetch requests that need to be resolved on the JS thread. Provides real wall-clock delays backed by Go timers.

func New

func New() *EventLoop

New creates a new EventLoop.

func (*EventLoop) AddPendingFetch

func (el *EventLoop) AddPendingFetch(pf *PendingFetch)

AddPendingFetch registers a pending fetch whose result will be delivered to JS when the HTTP response arrives.

func (*EventLoop) ClearTimer

func (el *EventLoop) ClearTimer(id int)

ClearTimer cancels a timer by ID.

func (*EventLoop) Drain

func (el *EventLoop) Drain(rt core.JSRuntime, deadline time.Time)

Drain fires all pending timers and resolves pending fetches until none remain or the deadline is reached. Must be called on the runtime's goroutine (JS engines are single-threaded).

func (*EventLoop) DrainPendingFetches

func (el *EventLoop) DrainPendingFetches(rt core.JSRuntime) bool

DrainPendingFetches does non-blocking reads on all pending fetch channels. For each completed fetch, it resolves/rejects via JS globals and removes it from the list. Returns true if any fetch was completed.

func (*EventLoop) HasPending

func (el *EventLoop) HasPending() bool

HasPending returns true if there are any active timers or pending fetches.

func (*EventLoop) RegisterTimer

func (el *EventLoop) RegisterTimer(delay time.Duration, isInterval bool) int

RegisterTimer creates a timer entry and returns its ID. The actual JS callback is stored in globalThis.__timerCallbacks[id].

func (*EventLoop) Reset

func (el *EventLoop) Reset()

Reset clears all timers and pending fetches. Called when a worker is returned to the pool.

type FetchResult

type FetchResult struct {
	Status      int
	StatusText  string
	HeadersJSON string
	BodyB64     string
	Redirected  bool
	FinalURL    string
	Err         error
}

FetchResult holds the pre-serialized outcome of an in-flight HTTP fetch. The fetch goroutine reads the response body, serializes headers, and encodes the body as base64 before sending — so the event loop only passes strings to JS.

type PendingFetch

type PendingFetch struct {
	ResultCh <-chan FetchResult
	FetchID  string
}

PendingFetch represents an in-flight HTTP request whose result will be delivered to JS via the event loop when the response arrives.

Jump to

Keyboard shortcuts

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