Last active
December 6, 2023 12:53
-
-
Save gvergnaud/6c79c8b50342b7572ef4921d6ba380f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type TaskPriority = "user-blocking" | "user-visible" | "background"; | |
export type SchedulerPostTaskOptions = { | |
// This priority is immutable and overrides the | |
// TaskController's priority. | |
priority?: TaskPriority; | |
delay?: number; | |
signal?: TaskSignal; | |
}; | |
export type Scheduler = { | |
postTask: <T>( | |
task: () => Promise<T> | T, | |
options?: SchedulerPostTaskOptions | |
) => Promise<T>; | |
}; | |
export type TaskControllerInit = { | |
// defaults to "user-visible" | |
priority?: TaskPriority; | |
}; | |
declare global { | |
interface TaskController extends AbortController { | |
readonly signal: TaskSignal; | |
abort(): void; | |
setPriority: (priority: TaskPriority) => void; | |
} | |
interface TaskSignal extends AbortSignal { | |
readonly aborted: boolean; | |
readonly priority: TaskPriority; | |
addEventListener( | |
event: "prioritychange" | "abort", | |
handler: (event: Event) => void | |
): void; | |
} | |
let TaskController: { | |
prototype: TaskController; | |
new (init?: TaskControllerInit): TaskController; | |
}; | |
let TaskSignal: { | |
prototype: TaskSignal; | |
new (): TaskSignal; | |
}; | |
let scheduler: Scheduler; | |
interface Window { | |
scheduler: Scheduler; | |
TaskController: typeof TaskController; | |
TaskSignal: typeof TaskSignal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment