Add fetchWorker for fetching off the main thread

This commit is contained in:
Alex Gleason
2023-11-28 18:44:23 -06:00
parent 81971df7fd
commit 3a85e3f8bf
7 changed files with 56 additions and 3 deletions

View File

@@ -0,0 +1,17 @@
import { Comlink } from '@/deps.ts';
export const FetchWorker = {
async fetch(url: string): Promise<[BodyInit, ResponseInit]> {
const response = await fetch(url);
return [
await response.text(),
{
status: response.status,
statusText: response.statusText,
headers: Array.from(response.headers.entries()),
},
];
},
};
Comlink.expose(FetchWorker);