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

Synchronous XHR processing not implemented #19

Open
retorquere opened this issue Sep 12, 2015 · 6 comments
Open

Synchronous XHR processing not implemented #19

retorquere opened this issue Sep 12, 2015 · 6 comments

Comments

@retorquere
Copy link

I'm trying to d a synchronous POST, but I'm getting "Synchronous XHR processing not implemented". code:

      req = new XMLHttpRequest()
      req.open('POST', 'http://localhost:23119/better-bibtex/schomd', false)
      req.send(body)
@pwnall
Copy link
Owner

pwnall commented Sep 13, 2015

@retorquere I looked into doing it, and everything I could find is really ugly. node's http libraries don't support synchronous requests, so I'd have to do a synchronous spawn and do all the processing in a child. This is a lot of work for a feature that most Web platform folks want deprecated.

On the bright side, there seem to be a few libraries doing synchronous HTTP, and that wasn't the case last time I looked into implementing synchronous XHR.

@retorquere
Copy link
Author

retorquere commented Sep 13, 2015 via email

@mhnsn
Copy link

mhnsn commented Aug 9, 2019

@retorquere Do you happen to have any recommendations? I'm working on a CLI app, and asynchronous behavior is breaking core functionality.

@jcde
Copy link

jcde commented Dec 12, 2019

xmlhttprequest package supports synchronous yet

@VirtualTim
Copy link

Ran into a painful debugging scenario before I realised that this module doesn't support sync XMLHttpRequest's. I might open a PR to at least throw an error if someone attempts to use this, to make debugging easier.

@jimmywarting
Copy link

I created to-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 'to-sync'

const toSync = createWorker()

const fetchSync = toSync(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

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

6 participants