Open
Description
I just created this async-to-sync package today that i named await-sync
it utilize web workers instead of spawning sync processes and data is transfered synchronous over SharedArrayBuffer
so less code needs to be copied over.
Therefore it's also more compatible with other enviorments like Deno, Bun, and also Web Workers.
it's as simple as just doing:
import { createWorker } from 'to-sync'
const awaitSync = createWorker()
const fetchSync = awaitSync(async function (...args) {
const res = await fetch(...args)
const ab = await res.arrayBuffer()
return new Uint8Array(ab)
})
const uint8 = fetchSync(url)
const text = new TextDecoder().decode(uint8)
const json = JSON.parse(text)
const blob = new Blob([uint8])
if you would use this instead then your package would have the possibility of being able to run in Deno, Bun.js and also Web Workers. but why web workers when you sync xhr...? that's a good question...
Metadata
Metadata
Assignees
Labels
No labels