Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check out await-sync #138

Open
jimmywarting opened this issue Apr 18, 2023 · 2 comments
Open

Check out await-sync #138

jimmywarting opened this issue Apr 18, 2023 · 2 comments

Comments

@jimmywarting
Copy link

jimmywarting commented Apr 18, 2023

I created await-sync today

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 'await-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])

check it out... it's very easy to use.
all the arguments is easily transferable over to the worker cuz it can use structural clone alg instead of passing things around with argv flags. or over stdin/out

so transfering blob / files are very easy. so there is no problem with re-creating a formdata on the worker thread.

@jimmywarting jimmywarting changed the title Check out to-sync Check out await-sync Apr 19, 2023
@MaddyGuthridge
Copy link

So glad to see this exists! The orphaned processes that sync-request leaves make it very difficult to deal with, so this will hopefully be a massive improvement. This looks like a great base library, does anything exist specifically for web requests?

@jimmywarting
Copy link
Author

In browser your could use Sync xhr in the main thread. But its being depricated.
Otherwise you could use Sync xhr in workers or use fetch along with await-sync but it requires enabling sharedArrayBuffer for the liv to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants