-
Notifications
You must be signed in to change notification settings - Fork 30
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
Implement async using workers #46
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for GitHub pages, due to modern requirements for SharedArrayBuffer
(after Spectre) and is a bit tacky by using a service worker that reloads the page with the needed headers set.
Ideally, GitHub pages would just set this header (like the the CORS headers), but that's not the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of modifying all the examples, I instead opted for backwards compatibility and added another example that does not use the raylib_js_set_entry
function (straight from the official examples).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would be called raylib.js
and the other file would be called raylib-worker.js
(instead of raylib.js
), but that would confuse git
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because python -m http.server
has no CLI options, this just starts http.server
with the additional headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to enable-threads.js
, python3 -m http.server
should work too, however this is more clean
Relates to #22 |
Oh damn, I was working on the same thing, you beat me to it! |
- automatically creates properties on both sides - types are synchronized for IDE users
- because we don't await start anyway, I removed the initialized reply
I toyed around with Web Workers, Atomics, SharedArrayBuffers and OffscreenCanvas and this actually makes most async tasks possible without using asyncify! This does not require any dependencies or code transformations, it is just the browser's web APIs.
Changes
raylib-wrapper.js
file that is the new main entry pointraylib.js
is run on a worker (not calledraylib-worker.js
to make git happy)SharedArrayBuffer
sAtomics#wait
server.py
script due to security requirements forSharedArrayBuffer
Closes #45