import { Agent, type GCMarker, type Job, type Markable } from '#self'; /** https://nodejs.org/learn/asynchronous-work/event-loop-timers-and-nexttick */ export type NodeJSJobType = 'timers' | 'pending callbacks' | 'idle-prepare' | 'poll' | 'check' | 'close callbacks'; export type EventLoopRunType = 'manual' | 'automatic'; export interface EventLoop extends Markable { /** * Enqueue a host job (macrotask) now. */ enqueue(type: NodeJSJobType | string, job: Job): void; /** * Enqueue a host job (macrotask) in the future. * It will keep `hasPendingJobs` to be `true` until `enqueue` is called. * * @example * ``` * eventLoop.enqueueAsync('timers', job, (enqueue, cancel) => { * setTimeout(() => { * enqueue(); * }, timeout); * }); * ``` */ enqueueAsync(type: NodeJSJobType | string, job: Job, executor: (enqueue: () => void, cancel: () => void) => void): void; /** Change the automatic run type of the event loop and run it */ run(type: EventLoopRunType): void; runOnce(): void; readonly hasPendingJobs: boolean; /** * Register a callback to be called when there are no async queued jobs. * * This can be used to implement a mechanism to exit the program when all code has finished executing. */ onNoPendingJob: Set<() => void>; } export declare abstract class AbstractEventLoop implements EventLoop { #private; protected readonly surroundingAgent: Agent; readonly onNoPendingJob: Set<() => void>; constructor(surroundingAgent: Agent); abstract enqueue(type: NodeJSJobType | string, job: Job): void; protected abstract shiftNextJob(): Job | undefined; protected abstract get hasQueuedJobs(): boolean; protected tryScheduleAutomaticFlush(): void; /** * Enqueue a host job (macrotask) in the future. * It will keep `hasPendingJobs` to be `true` until `enqueue` is called. * * @example * ``` * eventLoop.enqueueAsync('timers', job, (enqueue, cancel) => { * setTimeout(() => { * enqueue(); * }, timeout); * }); * ``` */ enqueueAsync(type: NodeJSJobType | string, job: Job, doAsyncEnqueue: (enqueue: () => void, cancel: () => void) => void): void; get hasPendingJobs(): boolean; /** Change the automatic run type of the event loop */ run(type: EventLoopRunType): void; runOnce(): void; mark(marker: GCMarker): void; } export declare class MicroTaskEventLoop extends AbstractEventLoop { enqueue(_type: string, job: Job): void; protected shiftNextJob(): Job | undefined; protected get hasQueuedJobs(): boolean; } /** https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide/In_depth */ export declare class WebLikeEventLoop extends AbstractEventLoop { protected jobsByType: Record>; protected queuedJobs: Map; /** * Enqueue a host job (macrotask) now. */ enqueue(type: NodeJSJobType | string, job: Job): void; protected shiftNextJob(): Job | undefined; protected get hasQueuedJobs(): boolean; mark(marker: GCMarker): void; } /** https://nodejs.org/learn/asynchronous-work/event-loop-timers-and-nexttick */ export declare class NodeJSLikeEventLoop extends AbstractEventLoop { #private; fallbackType: NodeJSJobType; protected jobsByType: Record>; protected queuedJobs: Set; enqueue(type: NodeJSJobType | string, job: Job): void; protected shiftNextJob(): Job | undefined; protected get hasQueuedJobs(): boolean; mark(marker: GCMarker): void; } //# sourceMappingURL=event-loop.d.mts.map