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

Fix race condition in webworker logic (hopefully) #18

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

DanielSherlock
Copy link
Contributor

Aims to fix issue #17.

Makes use of existing variable workerWorking to keep track of when worker is busy.
This starts off true, because the worker script takes a while to register it's own onmessage event handler (it has to wait for the gleam compiler to be available).
When the worker is ready, it sends a message with initialReadyMessage: true. If the worker hasn't yet compiled the initial code, this will cause it to do so.

Little Caveat: This version of the code relies on the editor's onUpdate event listener to send the initial message to the worker. If this turns out not to be reliable (see big caveat below), we can reinstate the line at the end which manually sends the first message.

Big Caveat: This code has so far only been tested using devtools. Having devtools open does change the behaviour of the original code (it reliably caused the otherwise-intermittent issue), so it may equally change the behaviour of this version of the code too. Ideally I would want to test it once the project has been built properly with gleam run, served to localhost, and probably with some network delay or whatever too. That's why this PR is a draft at the moment.

I've not got a working install of node on my machine (this is a target: javascript project), so testing this change may take me a little while, sorry.

@lpil
Copy link
Member

lpil commented Jan 23, 2024

Is this ready for review? Thanks!

@lpil lpil marked this pull request as ready for review January 23, 2024 14:02
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fab so I'm gunna merge! 😃

@lpil lpil merged commit ba9abad into gleam-lang:main Jan 23, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants