Skip to content

Conversation

@WhyPenguins
Copy link
Contributor

@WhyPenguins WhyPenguins commented Nov 26, 2024

Description

SplashKit Online has issues with concurrency, and has a variety of work-arounds in random spots to try and hide them. Rapidly clicking New Project for instance would cause errors, so we have a makingNewProject variable that we use to ignore the button while making a new project. Other similar issues such as loading a project, but clicking New Project mid-way, etc, could all cause issues such as database corruption and a broken IDE. It's also impossible to cancel any operations, including long running ones like loading demo projects.

This commit introduces the concept of Action Queues, which as the name suggests gives us synchronous queues in-which to perform actions (such as loading projects, initializing parts of the IDE, etc).

  • Action Queues simply run each action in their queue synchronously - one action must finish before the next begins.
  • Action Queues have queuing settings - it's possible to limit the maximum number of actions queued (typically to 1), to cancel currently running actions if a new one is queued in the same queue, and to remove other queued ones so later ones take precedence.
  • These queues can also have dependencies between each other - a queue will simply wait until the queues it depends on are empty. As an example, it doesn't make sense to Load a project until the project has finished being Initialized (database created, etc)
  • A queue can also clear itself upon change to another queue. For instance, it doesn't make sense to Load a project if after the load commences, the project is re-initialized.
  • As mentioned, actions in the queue can be cancelled. There's no way to do this explicitly in the interface, but as an example, starting a load of a demo project will be canceled by clicking New Project or loading a different project.

The commit adds a set of default action queues for the current set of actions that can be performed, and modified startup and loading code to use these queues.

This also allows the IDE to begin listening to events from the outside world immediately, as it can just queue up the actions those messages request.

Note: This code isn't very good 😋 I'd really appreciate if someone can review it in detail, or even better offer to finish tidying it up (in which case I'll merge it into a branch you can work off, and that branch can be merged into main once it's tidied).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • Documentation (update or new)

How Has This Been Tested?

Mostly just spam clicked around. Tested loading projects, new projects, loading demos, switching languages, etc. Honestly though there are still some minor errors that appear when really abusing the IDE - no worse than before though. Fixed! No errors show up at all now 😄

It really needs more testing, and there are a few spots in the code that should be tidied/refactored as well. Also improved, hopefully code quality is alright now anyway...

Testing Checklist

  • Tested in latest Chrome
  • Tested in latest Safari
  • Tested in latest Firefox

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have requested a review from ... on the Pull Request

 - it's really hard to trace where errors occur, at least
   like this we can see what the function that errored was.
 - normally I wouldn't commit something like this, but I think
   until this all gets cleaned up it's worth having better
   debuggability.
 - this is really just to fix a bad bug where if the user has a project
   named 'untitled', and for whatever reason that becomes not the
   'last opened' one, newProject attempts to create one with the same
   name which leads to an early error and a broken IDE
 - action queues always execute their queued up actions
   synchronously and in order
 - dependencies between action queues can be created, to make one
   wait until another is clear
 - action queues can also clear their contents if another queue is
   modified
 - IDE load and all project init/load functions now schedule their
   actions inside these action queues, and are also cancellable
 - this also means the IDE can now receive messages immediately
   upon loading - they will just be queued until their dependenciees load
@github-actions
Copy link

github-actions bot commented Nov 26, 2024

🐋 PR Preview!
The preview is no more!
Congrats if this was merged! 😄

# Conflicts:
#	Browser_IDE/editorMain.js
 - this is actually how it worked originally,
   how I change it was a mistake and could cause errors when loading
   demo projects
 - this makes mirroring more tolerant to directories already existing
   in the executable environment
 - really easy now! I like the action queues :P
 - we should add more tasks for converting everything to use them
   (should be easy, just needs a fair bit of testing)
 - now can really rapidly click to make/destroy projects
   and not have any errors at all!
 - key change was making a queue's 'clearOn' targets wait for the
   other queue to finish cancelling its action (done using new
   `synchronousWith` concurrency setting)
 - rationalized `Consume` loop a bit and made the logic clearer
 - simplified cancellation logic as well
 - made `projectFromZip` properly cancellable (it was a fluke that it
   'cancelled' previously, due to the 'key change' point above)
 - the Action Queues are still a bit more difficult to wrap one's
   head around than I wanted, perhaps there's a way to simplifiy this
 - but the IDE is more stable than ever, so yay!
@WhyPenguins WhyPenguins merged commit 56fc707 into thoth-tech:main Dec 2, 2024
2 checks 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.

1 participant