Fix race condition in webworker logic (hopefully) #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ownonmessage
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.