mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-06 15:14:23 +01:00
Add fetchWorker for fetching off the main thread
This commit is contained in:
17
src/workers/fetch.worker.ts
Normal file
17
src/workers/fetch.worker.ts
Normal 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);
|
||||
Reference in New Issue
Block a user