rsnext/packages/next/server/web/spec-compliant/fetch-event.ts

27 lines
738 B
TypeScript
Raw Normal View History

export const responseSymbol = Symbol('response')
export const passThroughSymbol = Symbol('passThrough')
export const waitUntilSymbol = Symbol('waitUntil')
export class FetchEvent {
readonly [waitUntilSymbol]: Promise<any>[] = [];
[responseSymbol]?: Promise<Response>;
[passThroughSymbol] = false
2021-10-26 17:29:17 +02:00
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(_request: Request) {}
respondWith(response: Response | Promise<Response>): void {
if (!this[responseSymbol]) {
this[responseSymbol] = Promise.resolve(response)
}
}
passThroughOnException(): void {
this[passThroughSymbol] = true
}
waitUntil(promise: Promise<any>): void {
this[waitUntilSymbol].push(promise)
}
}