happy-dom
Version:
Happy DOM is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG DOM and HTML.
47 lines (41 loc) • 965 B
text/typescript
import Response from '../Response.js';
/**
* Preload entry.
*
* @see https://html.spec.whatwg.org/multipage/links.html#preload-entry
*/
export default class PreloadEntry {
public integrityMetadata: string | null = null;
public response: Response | null = null;
public error: Error | null = null;
#callback: { resolve: (response: Response) => void; reject: (error: Error) => void } | null =
null;
/**
* On response available.
*
* @returns Response.
*/
public onResponseAvailable(): Promise<Response> {
return new Promise((resolve, reject) => {
this.#callback = { resolve, reject };
});
}
/**
* Response available.
*
* @param error
* @param response
*/
public responseAvailable(error: Error | null, response: Response): void {
this.response = response;
this.error = error;
if (!this.#callback) {
return;
}
if (error) {
this.#callback.reject(error);
} else {
this.#callback.resolve(response);
}
}
}