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(gs): Prevent duplicate minimap parts and use SinglePromiseInstance #127

Merged
merged 3 commits into from
Nov 12, 2023

Conversation

splixcord
Copy link
Contributor

@splixcord splixcord commented Nov 8, 2023

Prevent minimap parts appearing as duplicates or in the wrong place, this happens when the server or arena worker hangs long enough for more parts to be requested before the earlier one finished awaiting.
Fixes #130

@jespertheend
Copy link
Owner

I think it might still cause some issues this way because the arena.getMinimapPart() calls will start buffering.
Ideally the loop() doesn't make any new #updateNextMinimapPart() calls when one is already running, that should relieve the worker from some stress.

There's a couple of ways to go about this.

  • Renda comes with a SingleInstancePromise class which is meant for exactly this. Its usage should be pretty straight forward, but you can take a look at this file for an example.
  • You could set a boolean such as isUpdatingMapPart and then skip the call from inside the loop while it is set.
  • You could call #updateNextMinimapPart() from within a while (true) loop and await a promise that resolves using a setTimeout() within the loop. The server only has a single Game instance, but if it ever receives functionality to create and destroy Game instances, this loop will have to be cleaned up correctly.

I think I'd prefer the first option, since it doesn't rely on any 'global' state (the boolean getting set) and its name makes it clear why it's being used.

With one of these approaches your current changes technically wouldn't be necessary, but I still think it'd be nice to keep them around because it seems more robust.

@splixcord splixcord changed the title fix(gs): Prevent duplicate minimap parts fix(gs): Prevent duplicate minimap parts and use SinglePromiseInstance Nov 9, 2023
Copy link
Owner

@jespertheend jespertheend left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@jespertheend jespertheend merged commit d8ecf5c into jespertheend:main Nov 12, 2023
1 check passed
@splixcord splixcord deleted the fix/duplicateminimappart branch November 12, 2023 23:45
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.

Incorrect Minimap
2 participants