Documentation
¶
Index ¶
- type EventLoop
- func (el *EventLoop) AddPendingFetch(pf *PendingFetch)
- func (el *EventLoop) ClearTimer(id int)
- func (el *EventLoop) Drain(rt core.JSRuntime, deadline time.Time)
- func (el *EventLoop) DrainPendingFetches(rt core.JSRuntime) bool
- func (el *EventLoop) HasPending() bool
- func (el *EventLoop) RegisterTimer(delay time.Duration, isInterval bool) int
- func (el *EventLoop) Reset()
- type FetchResult
- type PendingFetch
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 (*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 ¶
ClearTimer cancels a timer by ID.
func (*EventLoop) Drain ¶
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 ¶
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 ¶
HasPending returns true if there are any active timers or pending fetches.
func (*EventLoop) RegisterTimer ¶
RegisterTimer creates a timer entry and returns its ID. The actual JS callback is stored in globalThis.__timerCallbacks[id].
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.