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 XMLHttpRequest on the main thread is deprecated #1596

Closed
mathiasrw opened this issue Dec 27, 2022 · 9 comments
Closed

Synchronous XMLHttpRequest on the main thread is deprecated #1596

mathiasrw opened this issue Dec 27, 2022 · 9 comments

Comments

@mathiasrw
Copy link
Member

image

image

@mintbomb27
Copy link

Hey! @mathiasrw Will switching the asy variable, with true solve the issue?

@mathiasrw
Copy link
Member Author

mathiasrw commented Dec 27, 2022

Yes and no.

Yes, it will solve the problem, but then we cant use this function for the sync calls expected when running the sync alasql command.

@mintbomb27
Copy link

So what would be the expected solution? To use another function like fetch() and make it synchronous?

@jimmywarting
Copy link
Contributor

There is a solution to turn anything async to sync, but that involves using Atomic.wait, it's the only thing that can halt the entire javascript thread. but Atomic.wait is only available within a web worker. and it requires an other thread to do the actual work, and then notifying the halted worker when it's done.
But Atomics also requires using SharedArrayBuffer. and using SharedArrayBuffer requires you to implicit enable it via response headers. Oh, and BTW, workers do not have access to localStorage, so it must ask the main thread for kv-pairs (via sharedArrayBuffers)

Sooo, yea this is truly annoying.
this is how absurd-sql manage to get a sqlite wasm to run in web workers and using Atomic.
there is a blog post about it here about how it went about implementing it: https://jlongster.com/future-sql-web#the-big-problem-sync-apis

but it's way easier in NodeJS... i made a sync blob reader just a few days ago: nodejs/undici#1830 (comment)
then KhafraDev made a bear minimum out of mine.

@jimmywarting
Copy link
Contributor

anyways i don't think there should even be a way to load data inside of alasql. i think it's the developers job to load the data it needs and then USE it as the data source.

Something in lines of:

const res = await fetch(url)
const ab = await res.arrayBuffer()
const db = new alasql.Database(ab)
const res = await fetch(url)
const ab = await res.arrayBuffer()
alasql(['ATTACH SQLITE DATABASE books(?); USE books'], ab)

@jimmywarting
Copy link
Contributor

To use another function like fetch() and make it synchronous?

fetch don't have sync functionality

@mathiasrw
Copy link
Member Author

fetch don't have sync functionality

Wrap the function in an async fn and use await inside to have it act as a sync call.

@jimmywarting
Copy link
Contributor

Some test started to fail inside browsers after removing sync compatibility. running in nodejs still passes the test.

@mathiasrw
Copy link
Member Author

mathiasrw commented Jan 16, 2023

Argf. We better get browser testing working in CICD so I dont introduce problems like this again.

image

https://github.com/AlaSQL/alasql/blob/develop/.github/workflows/Build%20and%20test.yml#L63

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

No branches or pull requests

3 participants